How to rollback datagridview value for invalid input?

In Datagrid, when I input a wrong value in a cell(say, letters in numberical cell), the datagrid automatically rollback to the original value.  How can I implement this in the new datagridview   
Note that I have tried to use e.Cancel=true in DataError event, but not success.
Thanks. 


Answer this question

How to rollback datagridview value for invalid input?

  • SAM SAM

    Hi,
    You can use the CellValidating event to validate the content of the cell. Set e.Cancel to true if the value is invalid. It will prevent the value from being committed and the user to leave the cell.
    Hope this helps.
    Thx, -regis

  • z2bass

    Yes, but that doesn't not rollback the value of the cell.  It just prevent from leaving the cell.  Moreover, I find that I can still leave the cell by clicking on a toolbar button, which even raise the event handler of the toolbar..

  • Scooter26

    Call the DataGridView.CancelEdit() method to cancel the current cell and have it roll back its value.

    Hope this helps!
    -mark
    DataGridView Progam Manager
    Microsoft
    This post is provided "as-is"

  • How to rollback datagridview value for invalid input?