Hello,
We have an ultraGrid with a templateAddRow on the top. When we click on a cell a row, we can edit it. In the last column of the TemplateAddRow, we added a button "+". If the user clicks on the button "+" or presses ENTER , the row is added to the grid after validating obligatory fields. Else, the data of templateAddRow is retained.
I tried with this code :
"private void UltraGridIndexOnBeforeRowUpdate(object sender, CancelableRowEventArgs e)
{
if (e.Row.IsAddRow && !_canAddRow) ultraGridIndex.RowUpdateCancelAction = RowUpdateCancelAction.RetainDataAndActivation; else ultraGridIndex.RowUpdateCancelAction = RowUpdateCancelAction.CancelUpdate; e.Cancel = !_canAddRow;
}
_canAddRow is a boolean which value is true when the button "+" or ENTER is pressed.
This code retains data of TemplateAddRow, but disables editing of the existing rows.
Any Ideas?
Thank you in advance.
Hello Amal,
I see that the e.Cancel = !_canAddRow; is outside the if statement, and no logic is applied to it. Therefore, this event would always cancel if no other logic is being applied to !_canAddRow outside of this event.
Hello John,
Thank you for your response.
Ok, you're right. I agree that e.Cancel = !_canAddRow; should be inside the if statement. I tried this :
private void UltraGridIndexOnBeforeRowUpdate(object sender, CancelableRowEventArgs e) { if (e.Row.IsAddRow) { if (!_canAddRow) { ultraGridIndex.RowUpdateCancelAction = RowUpdateCancelAction.RetainDataAndActivation; e.Cancel = !_canAddRow; } else { ultraGridIndex.RowUpdateCancelAction = RowUpdateCancelAction.CancelUpdate; } } }
But, I have the same problem ! When we edit the TemplateAddRow and click on an existing row, TemplateAddRow's data is retained and we cant't edit existing rows. What we want is when we click on an existing row, we can edit its values. Is this possible?
Amal
I meant to key in more to the fact that I don't see any logic being applied to the _canAddRow. So as far as I can see from your code snippets, _canAddRow will always be false once set to false, and you will get consistent behavior by checking it no matter what. Is there somewhere where you are setting _canAddRow back to true?
Most likely the issue is with the logic setting _canAddRow. You can verify this by setting a break point at the e.Cancel = !_canAddRow and checking what _canAddRow when you click the + button. My hunch is that it is false. From there the logic setting _canAddRow can be investigated as to why it's not setting correctly.
Please let me know if I can assist you further.
_canAddRow is back to true when we click on the "+" button or we press ENTER.