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.
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.
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).