How do I suppress the built-in validation in the UltraGrid for constraitns on DataTables (e.g. unique columns)? I need to allow the user to put in "invalid" data to a cell, but not leave the row. This means that I neither want to revert the value, nor keep the focus on that cell.
Also, I couldn't find any reference to the event model for validation in the online documentation. Does anyone know where I'd find this?
Hi,
By default, the gridwrites the contents of a cell to the underlying data source when the cell loses focus. So you won't be able to leave the cell in this case unless you change the grid's UpdateMode to something like OnRowChange or OnRowChangeOrLostFocus.This should allow the user to leave the cell, since the grid won't try to update the data source until they leave the row.
To handle errors in the grid, you can use the CellDataError event or the Error event (or possibly both). You would typically do any other validation in either the BeforeCellUpdate or BeforeRowUpdate events.
Mike,
That's one of the missing pieces! Thanks!
What I'm trying to do is provide our own custom validation through SetColumnError on the datatable used as the DataSource. What mechanism can I use to ensure that the user can't exit the row if there are errors? The UltraGrid doesn't seem to check for the presence of these errors by default.
Thanks in advance for your help.
Well, one possibility is that you trap the BeforeRowDeactivate event. You can get the underlying data row in the data source using the ListObject property of the row and check it for errors and if there are any, you can Cancel the event.
I am also tring to do the same things. I have to do some data check before i allow user to add new row in grid in client side.
I tried to write that code in BeforeRowInsertHandler client side event but i think the newly added row is not accessible at this point.
I tried to write the same code in BeforeRowDeactivateHandler, Newly added row is visible at this point but i could not restrict/Cancel to add new Row. Actually i am checking for date, If date is not selected, i want to enforce user to select date and do not want the user to see new row.
{
cellObj.setSelected(true);
}
In BeforeRowDeactivate, you can check e.Row.IsAddRow to determine if it's a new row.
You might be better off using BeforeRowUpdate, though, since BeforeRowDeactivate will fire for rows that have not been modified.
My guess is that cancelling BeforeRowUpdate doesn't keep focus on the row by default. Check out the BeforeRowUpdateCancelAction property on the grid. I think there's a setting that will help you get the behavior you want.
Thanks for your reply. I put the code on BeforeRowUpdate and tried to cancel the event if data is not validated. It clears the data , but still add rows. Am i missing any property to be set?