1

I have a huge DataTable instance bound to a GUI, next to the DataTable there lays a specialized object (let's call it ValuesIndex)implementing fast access to DataTable content. The problem is I need to keep ValuesIndex synchronized with the current state of the DataTable. When there are some values in DataTable which have not been accepted yet - I need to keep them in ValuesIndex. I also need to react properly to RejectChanges - so the whole ValuesIndex returns to its previous state.

Is there a possibility to set up event handlers for DataTable instance so the RejectChanges is catched? I tried to achieve that with usage of RowChanged event, but I cannot rely on that. If I delete a row from a table and then reject the changes, the RowChanged event is not called for some reason.

UPDATE: Turns out that I just deleted the rows the wrong way, instead of calling DataRow.Delete() I used DataTable.Rows.Remove. RowChanging event is fired both on AcceptChanges and RejectChanges

soliloquyy
  • 355
  • 3
  • 14
  • Why do you add another layer that needs to be maintained and synchronized at all? The `DataTable` provides already access to it's content and provides events to handle changes. So what is the benefit of your class if it makes all more complicated? – Tim Schmelter Mar 26 '14 at 12:34
  • I need to be able to quickly find row or rows which for column x carry value y. Iterating through the table is not an option. – soliloquyy Mar 26 '14 at 12:43
  • 1
    However, but the problem is not clear. Why don't you hold the `DataTable` as private property in your class and expose your own methods, properties and events? If the table can not be modified without your methods you have full control over your calculations. – Tim Schmelter Mar 26 '14 at 12:47

0 Answers0