public void AcceptChanges ()
{
EndEdit(); // in case it hasn't been called
+
+ _table.ChangingDataRow (this, DataRowAction.Commit);
switch (rowState) {
case DataRowState.Unchanged:
return;
// Accept from detached
if (_original != _current)
Original = Current;
+
+ _table.ChangedDataRow (this, DataRowAction.Commit);
}
/// <summary>
2005-05-04 Sureshkumar T <tsureshkumar@novell.com>
- * DataTableTest.cs: Added a test for DataTable. Should clear rows
- from indexes as well. Simplified table creation for ClearReset
- test.
+ * DataTableTest.cs:
+ - Added a test for DataTable. Should clear rows from indexes as
+ well. Simplified table creation for ClearReset test.
+ - Added a test to check whether Commit RowChanging & RowChanged
+ event is fired.
2005-04-29 Sureshkumar T <tsureshkumar@novell.com>
MyDataTable dt = (MyDataTable)(dt1.Clone());
AssertEquals("A#01",2,MyDataTable.count);
}
+
+ DataRowAction rowActionChanging = DataRowAction.Nothing;
+ DataRowAction rowActionChanged = DataRowAction.Nothing;
+ [Test]
+ public void AcceptChangesTest ()
+ {
+ DataTable dt = new DataTable ("test");
+ dt.Columns.Add ("id", typeof (int));
+ dt.Columns.Add ("name", typeof (string));
+
+ dt.Rows.Add (new object [] { 1, "mono 1" });
+
+ dt.RowChanged += new DataRowChangeEventHandler (OnRowChanged);
+ dt.RowChanging += new DataRowChangeEventHandler (OnRowChanging);
+
+ try {
+ rowActionChanged = rowActionChanging = DataRowAction.Nothing;
+ dt.AcceptChanges ();
+
+ AssertEquals ("#1 should have fired event and set action to commit",
+ DataRowAction.Commit, rowActionChanging);
+ AssertEquals ("#2 should have fired event and set action to commit",
+ DataRowAction.Commit, rowActionChanged);
+
+ } finally {
+ dt.RowChanged -= new DataRowChangeEventHandler (OnRowChanged);
+ dt.RowChanging -= new DataRowChangeEventHandler (OnRowChanging);
+
+ }
+ }
+
+ public void OnRowChanging (object src, DataRowChangeEventArgs args)
+ {
+ rowActionChanging = args.Action;
+ }
+
+ public void OnRowChanged (object src, DataRowChangeEventArgs args)
+ {
+ rowActionChanged = args.Action;
+ }
+
}