Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a way to know if the DataTable is dirty ??

Status
Not open for further replies.

TerDavis

Technical User
Sep 18, 2002
36
US
Hi,

I know that I can check the status of the individuals rows in a datatable to find out if they are dirty....
modified, deleted, added etc.

Is there a global flag on the datatable ?
If ( dataTable.changes == true ) than save

On Save, at the moment I am looping thru each row and checking its rowstate, but would be nice to know if i need to do this at all...

Thanks,
-ter
 
-ter,
I don't think (actually, I'm not sure) there is a property of the DataTable class that tells you whether its data has changed. However, you could use its RowChanged and ColumnChanged events along with a form-level variable to flag that data has changed. Take a look at this code:
Code:
[COLOR=blue]bool[/color] isDirty = [COLOR=blue]false[/color];

[COLOR=green]// Add a handler to the RowChanged event of
// the dt DataTable in the 
// InitializeComponents method[/color]
dt.RowChanged += 
   [COLOR=blue]new[/color] DataRowChangeEventHandler(Row_Changed);

[COLOR=blue]private void[/color] Row_Changed(object sender,
             DataRowChangeEventArgs e)
{
   [COLOR=green]...
   // Flag that data for the table has changed[/color]
   isDirty = [COLOR=blue]true[/color];
}
The isDirty variable will be true or false based on whether data in the table has changed.

Hope this helps!

JC


Friends are angels who lift us to our feet when our wings have trouble remembering how to fly...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top