Geting the Row count in response to RowDeleted
-
I am sure that .Net was sent to drive us all insane. I have a data grid bound to a datatable in a dataset. I have a label that displays the number of items in the grid, or shall we say it should ;-) I wanted to update the row count in response to RowChanged and RowDeleted, just set the label equal to DataTable.Rows.Count. But no, thats not updated until after the event has fired. Are there any events in DataTable, DataSet, DataView or anything else that fires _after_ the row count has been updated? Looks like I have to put some convulted logic in there to work out what the user is doing :-( Thanks Stephen.
-
I am sure that .Net was sent to drive us all insane. I have a data grid bound to a datatable in a dataset. I have a label that displays the number of items in the grid, or shall we say it should ;-) I wanted to update the row count in response to RowChanged and RowDeleted, just set the label equal to DataTable.Rows.Count. But no, thats not updated until after the event has fired. Are there any events in DataTable, DataSet, DataView or anything else that fires _after_ the row count has been updated? Looks like I have to put some convulted logic in there to work out what the user is doing :-( Thanks Stephen.
The order of events being triggered are as follows : - RowChanging - RecordStateChanged - RowChanged - and only then the Rows.Count value is updated (!) (
this.Rows.ArrayAdd(row);
) Since DataRowCollection (what you get with this.Rows) is an internal class, and on the other hand the collection itself (ArrayList) doesn't trigger any event when objects are added, updated or removed, I am afraid you are a bit bound to rely on code like this : - make sure to subscribe for all RowChanged events. - make sure to read the DataRawChangedEventArgs .Action property passed along with it, and check for one of these actions {Add, Change, Commit, Delete, Nothing, Rollback}. - then, from the current Row Count value, and this action, just try to guess the final Row Count value. (*) - alternatively to (*), create a short life timer in your RowChanged event handler and let it go. Then get the actual Row Count value when the timer signals. -
The order of events being triggered are as follows : - RowChanging - RecordStateChanged - RowChanged - and only then the Rows.Count value is updated (!) (
this.Rows.ArrayAdd(row);
) Since DataRowCollection (what you get with this.Rows) is an internal class, and on the other hand the collection itself (ArrayList) doesn't trigger any event when objects are added, updated or removed, I am afraid you are a bit bound to rely on code like this : - make sure to subscribe for all RowChanged events. - make sure to read the DataRawChangedEventArgs .Action property passed along with it, and check for one of these actions {Add, Change, Commit, Delete, Nothing, Rollback}. - then, from the current Row Count value, and this action, just try to guess the final Row Count value. (*) - alternatively to (*), create a short life timer in your RowChanged event handler and let it go. Then get the actual Row Count value when the timer signals.Thanks for that, I had come to the same conclusion, but it's good to hear it from someone else. I wounder if any of this behaviour has changed in V1.1 of the framework? Stephen.