Hi
I would like to suppress the new template row add to the grid when the existing template row is not filled with valid data. Which event should I cancel to suppress the new template row at the bottom?
Also, I see that RowEditTemplateRequested event is not fired at all.
Is this order of firing these events?
1) RowEditTemplateRequested
2) IntializeTemplateAddRow,
3) BeforeRowEditTemplateDisplayed
Thanks
RowEditTemplate is not the same as a TemplateAddRow. These are two totally different areas of functionality.
I don't think it's possible to cancel the new TemplateAddRow once you start editing an existing row. What happens is that once you enter a TemplateAddRow and begin to edit a cell, the TemplateAddRow becomes an Add Row and it no longer a TemplateAddRow. So a new TemplateAddRow has to be shown. Otherwise, the AllowAddNew setting would no longer be valid since there would be no template add row.
So it seems to me that you have a couple of options.
1) You could use BeforeRowUpdate and/or BeforeRowDeactivate to prevent the user from leaving the Add Row once they start editing until the row is completely filled in.
2) You could set AllowAddNew to No and then add rows to the grid in code or via the AddNewButtons so that you have full control over when the new rows are created.
Hi Mike,
I'm canceling the BeforeRowDeactivate event when the row is not valid and that works fine when moving away to another row, but this fails when I click outside the Grid and another control gets focused. It seems that cancelling the BeforeRowDeactivate event does not prevent the grid from losing focus. I would like to prevent the user from leaving the row until they either fix the problem or cancel the update by pressing Esc.
Perhaps you need to do the same check in the Validating event of the grid, then?
Simple enough. Works great. Thanks
Hi,
One thing you could try is handling BeforeRowDeactivate. You could check IsAddRow and if it's true, call CancelUpdate on the row.
Yes, by saving I mean commiting the data to the db.
This is how I would like the grid to behave:
When row.IsAddRow == false
So the only issue really is how to prevent the AddRow from being commited when the user does not press Return/Enter or tabs out of the row. The problem is that in BeforeRowUpdate for the AddRow I don't know if the user is moving away from the row or has pressed Enter.
I don't understand... What exactly do you mean by "I try to save the row in the BeforeRowUpdate". What exactly are you saving? You don't have to manually write the grid data to the data source, the grid will do this automatically. Do you mean you are writing the data to the back end?
BeforeRowUpdate should still fire, whether the row is a new row or an existing row. You can check row.IsAddRow to see which one it is.