Description:
In my scenario, data is updated at the data source level. I wish to catch this moment and perform a side operation. Is there a Grid event raised when the data source value is changed? I already tried the CellValueChanged event, but it doesn't fire when I change a cell value. What can I do?
Answer:
As you correctly mentioned, the CellValueChanged event is not raised in this case. The list below gives possible reasons why this event is raised:
-An end-user has closed an in-place editor after changing the editor's value.
-A cell's value has been changed using the methods provided by Views.
For instance, the SetRowCellValue method can be used for this purpose. The event doesn't fire when a cell's value is changed using the methods provided by the data source.
If in your scenario it's necessary to react to value changes in the Grid's data source, use events provided by your data source.
Let's assume that you are using ADO.NET DataSet as a Grid's data source. In this case, handle DataTable's RowChanging or RowChanged event. Please refer to the Handling DataTable Events MSDN help article for additional information.
If the Grid is bound to BindingSource or BindingList, handle the corresponding BindingSource.ListChanged and BindingList<T>.ListChanged events. ListChanged notifications for item value changes are only raised if the list item type implements the INotifyPropertyChanged interface.
Note that you can also use a more common approach applicable to different sources. This approach implies the use of the CurrencyManager class, which provides the CurrencyManager.ListChanged event as well. Please refer to the CurrencyManager.ListChanged help article and take special note of the Remarks section to see when this event can be raised.
Adding and deleting records can be handled the same way if for some reason, Grid events cannot be used directly (e.g. when the UI layer cannot communicate with the data layer). If your scenario is more complex and you cannot decide what approach suits your needs better, feel free to contact our Support Team and describe your use-case in greater detail.