hi,
I have a problem with the grid updatemode. No matter what I set the mode as, the underlying datatable still get updated as soon as cell update event.
what i need to do :-
compare the value of columns before and after row update.
cannot do this in cell update event because i need to compare multiple columns at one time.
cannot use cell original value because it always keep the last value changed, not the most current value before row update.
tried to use before row update, but no idea how to get the respective cells value before the update
any idea ?
thanks
Hi,
If you set UpdateMode to OnRowChange or OnRowChangeOrLostFocus, then you could use BeforeRowUpdate to compare the values in the cells to the values in the underlying data source.
To get the object in the data source that the grid row represents, you use the ListObject property on the row. If you are using a DataTable, then the ListObject property will return a DataRowView, which has a Row property on it, so you can get the DataRow and examine it's data and compare that to the Value of the cells in the grid row.
Hi Mike,
It is not working, the datatable or the listobject already been changed even set to rowchange mode.
I'm sorry, I think I misunderstood the issue. The behavior you are getting here is correct. The UpdateMode property controls when the grid calls EndEdit and thus commits the changes into the row. But the values of each field as still written to the data source when you leave a cell.
If you want to get the original values from the rows, you can use the DataTable's GetChanges method.
No, it won't work for datatable to getchanges, cuz there is no changes at all before the row update. It will simply return nothing. I m confused by the rowupdate mode caused the update to the datasource and the event didnt even supply the before update value for evaluation.
Any idea how can i accomplish that ?
caspers said:No, it won't work for datatable to getchanges, cuz there is no changes at all before the row update
I'm not sure I follow you here. The whole crux of this discussion is that there ARE changes. The grid has already written the changes to the DataTable, so if the DataTable is not returning any changes at that point, then something is seriously wrong with the DataTable implementation.
sorry not to make myself clear.
datatable getchanges will only return something if there is AT LEAST 1 row changes has been committed to it. For the case that if I make changes on multiple cells for the 1st time before the BeforeRowUpdate event, the row is not committed to the datatable, so datatable getchanges will return nothing back. Yet, the datatable values have been changed though.
For instance, follow the steps with my attached project given earlier, when you make changes on the 1st row and then click on 2nd row, the values of the datatable have changed but datatable getchanges return as NOTHING.
Thanks
Okay, I did a little more research into this, and it looks like the indexer in the fields for a DataRow has some overloads which takes a DataRowVersion.
So if you do this, you get the modified value:
void ultraGrid1_BeforeRowUpdate(object sender, CancelableRowEventArgs e) { DataRowView drv = e.Row.ListObject as DataRowView; Debug.WriteLine(drv.Row["String 1"], "Original Value"); }
But if you want the original value, you can do this:
void ultraGrid1_BeforeRowUpdate(object sender, CancelableRowEventArgs e) { DataRowView drv = e.Row.ListObject as DataRowView; Debug.WriteLine(drv.Row["String 1", DataRowVersion.Original], "Real Original Value"); }
I could use the DataRowVersion.Current instead of original for the most latest value before the row committed to datatable since the original is giving the very 1st value before calling acceptchanges.
Thanks for your help.