When a user is trying to modify a cell value in the grid, I want to validate the date that is being entered and display a modified value.
Like, if the user enters a name with leading and trailing space " abc ", I want to trim the string and display the modified value (just "abc").
I tried the following,
In CellUpdaing event
e.cell.value = newValue //didn't work.
CellValuePresenter.FromCell(e.Cell).Editor.Value = newValue //also didn't work
Hello Viswanath,Thank you for the provided code-snippet.I have been looking into your issue and the reason for the CellUpdating event not to work is because the value of the current cell has not been updated yet (it is still in the process of updating) at the time you are handling the event.In order to trim the value of your cell, you will have to make sure the user has finished typing and then you will be able to get the value and change it. You should be able to do this by handling the CellUpdated event (the updating has finished and we can get the current value) of the XamTreeGrid as I have done in the code snippet below.private void XamTreeGrid_CellUpdated(object sender, CellUpdatedEventArgs e){ if (e.Cell.Value is string) { e.Cell.Value = ((string)e.Cell.Value).Trim(); }}If you require any further assistance on this matter, please do not hesitate to ask.
The reason I was trying to perform this operation in "CellUpdating" instead of "CellUpdated" is,
I have some validation that I am performing on the data the user enters in the cell. If the user enters invalid data, I want to cancel the operation, which I can do by e.cancel = true in "cellUpdating".
If I have to do that in "CellUpdated", I am not sure how to obtain the previous value that used to be in the cell as it is already overwritten.