Hi, I'm new to UltraGrid, and need your help.
I'm trying to solve this by myself but with no success.
Using VB, or C#, no problem, what is the right sequence that I should check the events, in order to verify the user input?
I want the user to be able to insert new rows (I have a button for that), delete (also have a button) and update (simply start writing). But I must verify if all the cells have good values before I save it to the DataTable, and after that to the database.
I would like to be able to prevent the user form clicking outside the grid, during an Insert (new row) o update.
I appreciate your help. I don't want you to make my work, just point out the guidelines and if possible where I can find some examples. I already searched everywhere, but didn't find much help.
Hope you can help me on this, because I already spent more then 3 days trying it out with no success.
Thanks in advance. Best regards.
Hi,
There are a number of ways you can handle validation in the grid. If you want to validate the entire row at once, then the best event to use would be BeforeRowUpdate. This event will fire both for new rows and existing rows any time the user tries to commit the changes to that row. You can tell the different by checking the IsAddRow property on the grid's ActiveRow. If it's true, it's a new row, otherwise, it's an existing row.
The event gives you the ability to cancel the changes and there's a property on the grid called BeforeRowUpdateCancelAction which gives you some options for what happens when the event is cancelled.
You could also choose to validate data on a cell-by-cell basis. You could use BeforeCellUpdate or BeforeExitEditMode for this, depending on your needs. You can also apply some validation rules to the grid using the UltraWinValidator component.
Hi, thanks for your help. I have yet some unanswered situations.
I defined .UpdateMode.OnUpdate. When should I can the update method? After what event?
How can I prevent the user from clicking outside the grid during an update or insert? He/she shouln't be able to click on controls (textbox,...) or on buttons (command buttons, menus,...). How to prevent this? I tried BeforeCellDeactivate, but this event doesn't fire in all situations, or when it fires it's too late (if I click in a textbox, for instance, it only fires this event when the grid gets focus again, and not before).
Tavinfor said:I defined .UpdateMode.OnUpdate. When should I can the update method? After what event?
I'm not sure, but I don't think the OnUpdate option works in DotNet. This option was carried over from the ActiveX version of the grid. But I think the BindingManager in DotNet implicitly calls EndEdit whenever the current position changes, so the grid will probably end up committing the changes any time you leave the row, anyway.
If you want to validate the data for each cell individually, then I would use OnLostFocusOrCellChange. If you want to validate a whole row at a time, use OnLostFocusOrRowChange.
Tavinfor said: Hi, thanks for your help. I have yet some unanswered situations. I defined .UpdateMode.OnUpdate. When should I can the update method? After what event? How can I prevent the user from clicking outside the grid during an update or insert? He/she shouln't be able to click on controls (textbox,...) or on buttons (command buttons, menus,...). How to prevent this? I tried BeforeCellDeactivate, but this event doesn't fire in all situations, or when it fires it's too late (if I click in a textbox, for instance, it only fires this event when the grid gets focus again, and not before).
I think you would probably have to use the Validating event of the grid in order to prevent it from losing the focus entirely. I'm not sure if this is feasible, though, since the grid often uses child controls for cell editing.
Mike,
I've searched the Methods collection of UltraGrid and can't find a OnLostFocusOrCellChange event.
Am I misunderstanding something?
I was referring to the UpdateMode property (and it's enum values) of the grid, not a method.
There is no OnLostFocusOrCellChange event or Enum, but there is an enum OnCellChangeOrLostFocus.