Click here to Skip to main content
13,052,696 members (65,366 online)
Rate this:
Please Sign up or sign in to vote.
See more:
how to use column changed event of datatable.
I am working with column changed event .my code is below.....

private void getDataTable()
           DataTable _dt = new DataTable();
           _dt.Rows.Add("Anamika", "21");
           _dt.Rows.Add("anu", "18");
           _dt.Rows.Add("aman", "21");
           _dt.Rows.Add("Ankush", "19");

           _dt.ColumnChanged += new DataColumnChangeEventHandler(_dt_ColumnChanged);
           _dt.Rows.Add("amika", "21");
           _dt.Rows.Add("akansha", "19");
       private static void _dt_ColumnChanged(object sender, DataColumnChangeEventArgs e)
           Console.Write(e.Column.ColumnName + " changed to '" + e.ProposedValue + "'\n");

But my code does not show result.and when i put the breakpoints on _dt_ColumnChanged method then this delegate method not called.
pl z give me solution of this.
Thanx and Regard
Posted 11-Jul-13 1:03am
Updated 11-Jul-13 19:17pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

At the end of getDataTable(), the object _dt goes out of scope and therefore dies.

Very likely, there is another DataTable in your application and that is the one that you actually want to change.

Or you want to bind _dt to a DataGridView[^] that is visible on one of your application's forms as its DataSource[^].
In this case, bound to another object, the instance _dt, although no longer reachable through that identifier, will live on and show its values through the DataGridView.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


As specified in this MSDN[^] link, ColumChanged event will
Occurs after a value has been changed for the specified DataColumn in a DataRow

That means event will be raised when something changed in the row. In your example, you are adding rows in to table, and not changing the values of any column.

If you just add following piece of code in your getDataTableMethod then you would hit the breakpoints in _dt_ColumnChanged

foreach(DataRow row in _dt.Rows )
            row["Age"] = "21";

Ankush Bansal

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 14 Jul 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100