Hi,
I'm using a grid with AllowAddNew set to AllowAddNew.FixedAddRowOnTop and in BeforeRowUpdate I make some validation to decide if changes will be updated in the data source or not. When validation failed I set e.Cancel to true to cancel update, this work fine but the row (that is the add row template) become a non add row template that means that IsAddRow property return false, even after pressing ESC the row still non add row template and this is a problem for me because I'm setting some row properties based on this propertie.
How can I reset the add row template?
Best regards.
Okay, I was with you up until the end of your e-mail and then you lost me.
Your original post was talking about cancelling the row in code becuase of failed validation. But now you are saying the user is pressing escape.
Also, I don't see how IsAddRow and IsTemplateAddRow can both be false in this case. The row should still be an AddRow, since it has unsaved changes and has not been comitted to the data source. Are you sure you are looking at InitializeRow for the correct row? If that's the case, then it sounds like it might be a bug.
Can you create a small sample project that demonstrates this? If so, post it here, and I will be happy to take a look at it.
Thank you, it's well explained but that does not help me, I will provide the exact scenario for my problem :
I have a column with buttons with 'add' image if the row is the templateAddRow and 'delete' image for other rows and I 'm setting this in this way :
private void gridTemp_InitializeRow(object sender, InitializeRowEventArgs e) {
if (e.Row.IsAddRow)
e.Row.Cells[COLUMNS_COUNT - 1].ButtonAppearance.Image =addButtonImage; else e.Row.Cells[COLUMNS_COUNT - 1].ButtonAppearance.Image = deleteButtonImage; }
After editing this row to enter new record and pressing <Enter> i make some validation in BeforeRowUpdate when it's invalid I set e.Cancel to true and I set the rowUpdateCancelAction like this :
if (e.Row.IsAddRow) { gridTemp.RowUpdateCancelAction = RowUpdateCancelAction.RetainDataAndActivation; } else gridTemp.RowUpdateCancelAction = RowUpdateCancelAction.CancelUpdate;
(I want to discard changes when editing existing record and retain data for the add row )
When user press <ESC> to cancel entering new record and click in the row the delete image appears in the button instead of the add image because in the gridTemp_InitializeRow this row is neither IsAddRow nor IsTemplateAddRow.
I hope that I was clear in my explanation (I'm not good in english).
When you have a TemplateAddRow in the grid, it has no corresponding row in the data source. At this point, IsAddRow will return false - because the row is not actually an AddRow, it's a TemplateAddRow. So there's another property on the row called IsTemplateAddRow that will return true.
As soon as the TemplateAddRow gets focus, either by clicking on it of tabbing into it, or in code - a row is added to the data source and the row ceases to be a TemplateAddRow and becomes an AddRow.
When you cancel the row, the row in the data source is cancelled and remove and thus the row returns to it's original state where it's a TemplateAddRow and not an AddRow any more.
So it sounds like maybe your code needs to check for IsTemplateAddRow as well as IsAddRow.