Technologies: C#, .Net, Winforms
I have a main form that pulls data from a database, and populates numerous different controls. Labels, Textboxes, DataRepeaters, DataGridViews, and tabs filled with those kinds of controls as well.
However, the data is also being pulled in such a way that there are multiple “records” on this form being navigated by a BindingNavigator.
Because of the structure of my code, I can’t easily call a DataAdaptor.update() on whatever control is being validated, (using it’s associated DataTable) so I’m just going to use a commit button instead.
What I’d like to know is “How do I check all the controls to see if they’ve been edited?”
I’m using the binding Navigator buttons as the trigger to “FindEditedControls()”
Current Solution:
DataTable dt = db.GetTable();
dt.RowChanged += new DataRowChangeEventHandler(dtUpdated);
private void dtUpdated(object sender, DataRowChangeEventArgs e)
{
needsCommit = true;
}
And the button just checks the needsCommit boolean variable. If it’s true, then it asks the user to commit the changes before continuing. If they click “Yes” then it commits the data to the database.
If this is what you were getting, I want to thank you. This works very nicely with DataGridViews. Now to test it with standard form controls.
Hook up to the
DataTable.RowChangedevent. When it fires, one of your controls has been edited.Then, you can check the
DataRow.RowStateproperty for a value ofDataRowState.Modifiedfor the rows you are binding to.