I am having some problems using win grid. Following is my scanrio.
I have a data gird bound with a bindingsource.
On row update, I need to fetch the row data before it was updated . I tried to catch BeforeRowUpdate(sender,e) event. It gives me new values. If I try to get value from dataset against e.Row.Index (index of row passed to BeforeRowUpdate event), it again gives me the new value entered in the gird cell.
Kindly help me out with this. I am stuck in the middle of no where because of this problem.
Thanks in advance,
wjz said:After changing the value of a cell, if I click on some other control (ie the grid loses focus), the .Value property reflects the previous cell value, and the .Text property reflects the current cell value (with formatting)
If the Value is still returning the previous value, then my guess is that the grid is not losing focus. You are probably clicking on a control that does not take focus away from the grid, like a toolbar button or something.
If that's the case, then you should call UpdateData on the grid, or Update on the grid's ActiveRow to commit the changes before you try to read the cell value.
Regarding getting the original value of the cell, the grid writes it's changes into the data source any time you leave the cell. It has to do this. The UpdateMode only controls when the grid calls EndEdit on the BindingManager. If you need the original value of the cell, you can get it from your data source, assuming your data source tracks these changes. There's a discussion of this technique here:
grid updatemode does not work with datatable - Infragistics Community
With the UpdateMode set to OnRowChangeOrLostFocus, and with a grid bound to a datatable, I have run into 2 scenarios if I place a breakpoint in the BeforeRowUpdate event and then make a change to a cell. After changing the value of a cell, if I click on some other control (ie the grid loses focus), the .Value property reflects the previous cell value, and the .Text property reflects the current cell value (with formatting) - However, if I click onto some other row in the grid, the .Value property and the .Text property both reflect the current cell value. I have set up a simple test form, and I cannot replicate my issue. So there must be some properties we are setting in our base class that is causing this erratic behavior, but I don't know what property I could possible set to cause it.
So my problem is that I cannot reliably get the current value, and your problem is that you cannot seem to get the previous value. With regard to your problem, the only way that I have reliably been able to trap the previous values of a grid row prior to update is to capture them in the AfterRowActivate event in some structure that is visible to the entire form, and then use those values in the BeforeRowUpdate event. If you extend the grid, or if all of your forms are using a base class that you inherit from, you can set this up pretty easily in a standard way.
yep, this is horrible, no matter what I set the grid's update mode as, the underneath datatable changed right away after the cell update event.
Any solution to prevent the grid to update the datasource ?
thanks
I ran into the same issue as the OP and found out that when you're using a custom datasource, your custom object must implement IEditableObject.
The grid updates the cell value to the underlying object before BeforeRowUpdate is raised. I am guessing this has to do with how BindingManager works (per Mike? or someone from Infragistics I think) with position changes which is mentioned in this forum somewhere. Another workaround would be to catch BeforeCellUpdate. I used it before but was trying to find a simpler way. Now my UI code is simpler but custom object is more complex. Pick your poison...[UPDATE]
I realized after posting that my scenario is with respect to canceling an update in BeforeRowUpdate, which will not work without IEditableObject support.
[Update2]
I am getting some other issues implementing IEditableObject:
ex)
So for now, I am going back to handling BeforeCellUpdate event.
p.s. Is there a code sample out there that implements IEditableObject which works correctly with UltraWinGrid?
I'm not sure why that's not working. How are you accessing the value of the underlying data row inside BeforeRowUpdate? Are you using the ListObject as I suggested?
What kind of data source are you using for the grid? Is it a DataTable? I think the DataTable tracks changes so you might be able to get the old values from that, even if they have been updated by the grid.