DataRowState Not Working
-
I have a database application that has a datatable bound to both a DataGridView and some text boxes. The text boxes, collectively, show one row of data. Now, if a user has edited a row and clicks 'Save' in the File menu, I want those changes to be saved. Right now, I'm basing the decision to save or not save a row on whether the DataRowState for that row is 'Modified'. But, if the row the user has edited still has the 'focus', so to speak, the DataRowState is not 'Modified', but 'Unchanged', even if the individual values in the text boxes (to which the data table is bound) have been changed. As soon as I go view another row in the database, though, the DataRowState becomes 'Modified'. Is there an easy way to validate the row without leaving it?
-
I have a database application that has a datatable bound to both a DataGridView and some text boxes. The text boxes, collectively, show one row of data. Now, if a user has edited a row and clicks 'Save' in the File menu, I want those changes to be saved. Right now, I'm basing the decision to save or not save a row on whether the DataRowState for that row is 'Modified'. But, if the row the user has edited still has the 'focus', so to speak, the DataRowState is not 'Modified', but 'Unchanged', even if the individual values in the text boxes (to which the data table is bound) have been changed. As soon as I go view another row in the database, though, the DataRowState becomes 'Modified'. Is there an easy way to validate the row without leaving it?
-
Just a guess, but you might try calling the EndEdit method on the DataRow prior to checking its DataRowState.
I thought of that, too, but it did not work. When I googled the problem, I found a solution. Basically, if I call the BindManagerBase.EndCurrentEdit() method, that updates the datatable with any changes that are in progress and changes the DataRowState, as appropriate.