Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
335
Validate and modify cell value while CellUpdating
posted

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

Parents
No Data
Reply
  • 6365
    Offline posted

    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.

Children