Fog Creek Software
Discussion Board

Welcome! and rules

Joel on Software


I need to do this: have the user enter data into a data grid.

After the user finishes editing a cell (by pressing TAB, ENTER, down arrow, etc), I have to do something (that is, execute some code).

I tried this:

dataSet11.products.RowChanging+=new System.Data.DataRowChangeEventHandler(RowChangeHandler);

dataSet11.products.RowChanged+=new System.Data.DataRowChangeEventHandler(RowChangeHandler);

protected void RowChangeHandler(object sender, System.Data.DataRowChangeEventArgs e)
  MessageBox.Show("Inside event handler for RowChangeHandler");

The problem is - the event handler NEVER executes, no matter what kind of edits I do to the DataGrid!



Is there any way I can do what I need to do - that is, do something (execute some code) when the user changes some data in the datagrid?

Thank you!

John K.
Sunday, June 29, 2003

There's always a's just a matter of finding it in the giant swamp that is the .NET Framework. The RowChanged event isn't going to help you, because it isn't posted until something triggers the entire row to change (like the user moving to another row in the DataGrid).

From what you're describing, you're going to need to work with the DataGrid rather than the underlying DataSet, because the DataGrid is going to cache the changes as long as the user doesn't leave the row. You'll probably need to handle the CurrentCellChanged event of the DataGrid.

Based on your recent questions, I'd suggest you take a look at the DataGrid section of George Shepherd's Windows Forms FAQ - . He's covered most anything you might want to do in a DataGrid, with lots of sample code available. It's saved me from hours of banging my own head on the wall seveal times.

Mike Gunderloy
Sunday, June 29, 2003

*  Recent Topics

*  Fog Creek Home