Hi,
I assign a ValueList to a cell: -
Infragistics.Win.ValueList vl;
vl = grid.DisplayLayout.ValueLists.Add("TestValueList");
vl.ValueListItems.Add(1, "A");
vl.ValueListItems.Add(2, "B");
grid.DisplayLayout.Bands[0].Columns[2].ValueList = grid.DisplayLayout.ValueLists["TestValueList"];
Then at UltraGrid.AfterCellUpdate(): -
private void grid_AfterCellUpdate(object sender, Infragistics.Win.UltraWinGrid.CellEventArgs e)
{ …
grid.EventManager.SetEnabled(Infragistics.Win.UltraWinGrid.GridEventIds.A fterCellUpdate, false);
if (e.Cell.OriginalValue.ToString() == "A")
{ e.Cell.Value = 1; }
else
{ e.Cell.Value = 2; }
grid.EventManager.SetEnabled(Infragistics.Win.UltraWinGrid.GridEventIds.A fterCellUpdate, true);
}
However, I couldn’t get a consistent value back at the e.Cell.OriginalValue: -
Original value selected is A
Test attempt
Value
Text
OriginalValue
Select “B” in the list
2
B
A
Select “A” in the list
1
Why the OriginalValue sometimes return me Text of the value list and sometimes is the selected index?
How can i restored the original value?
Thanks
I don't think setting the cell's Value property in response to AfterCellUpdate is a good idea, because at that point it is in the process of committing the last value it had. In any case, the reason that sometimes the text is returned and sometimes the value is returned is because our ValueList behaves like a ComboBox control insofar as, when there is no selected item, the text typed by the user is returned as the value.
The cell's original value is maintained during the course of an edit mode session, so that if the user presses escape (synonymous with canceling the BeforeExitEditMode event), the cell's value is reverted. At the time AfterCellUpdate fires, on the other hand, it has already been committed and the "original" value is lost.
It would seem possible that you are mistaken about the expected function of the AfterCellUpdate event, and you should be using BeforeExitEditMode instead.
I did try to use BeforeExitEditMode event, however, this event get triggered each time I click on the cell even though there is no changes made.
Testing shows me that once I change the cell’s value and save to database, the second time I click the cell again but without changing the cell’s value will still trigger the event. However, the original value is the one in the 1st attempt to save into database, so I cannot do a comparison whether are there really any changes to the cell’s value.
Appreciate any suggestion?