I have an UltraGrid that uses an UltraDataSource as the datasource.
I validate the users input in the CellDataUpdating event.
The scenario is when the user has entered an invalid value and then clicks on another row using the mouse.
The test runs fine and the error message is shown.
The problem is that the cell that the user has clicked becomes the active cell and not the cell the user added an invalid value to.
How do I make this happen?
Okay, sorry for the confusion. I wasn't clear on what you were doing here.
I assumed that if you are cancelling the update on the data source like you are doing here that you would also throw an exception to notify the user that a problem occurred.
I don't think there's any way the grid can know that the operation was cancelled, otherwise.
The only other way I can think to do this would be to validate using the grid events, rather than the DataSource events. You could handle BeforeExitEditMode or BeforeCellUpdate and do your validation there.
What do you mean by "If you are raising an error on the data source"?
What I do is this:
private void ultraDataSource1_CellDataUpdating(object sender, CellDataUpdatingEventArgs e)
{
e.Cancel = true;
}
Would you call this "raising an error"?
Neither the CellDataError nor the Error events are fired.
Is there a way to make sure the events are raised?
If you are raising an error on the data source, then the grid's CellDataError event or possibly the Error event will fire. Check out these events and see if the event args have properties to allow you to stop the grid from losing focus.
If that doesn't work, then you probably have to use the grid's BeforeCellDeactivate or BeforeExitEditMode events.