Hi,
I have a win grid with the new row template at the top and combo box outside the panel of the grid. When i click on the new row template, start editing it and leave before filling all the fields (i.e. i click on some other field outside grid panel), the new row gets added to the grid which is undesirable as few of the mandatory fields are left blank. The new row needs to be validated before getting added to the grid.
I added this event BeforeRowUpdate and doing the following to validate the fields.
Though i am able to validate this way, but the partially filled new row is getting lost after this instead of being retained.
void gridOwner_BeforeRowUpdate(object sender, CancelableRowEventArgse)
{
if (e.Row.IsAddRow)
foreach ( UltraGridCell item in e.Row.Cells)
if (item.Value.ToString().Trim().Length <= 0 && !item.Column.Hidden)
MessageBox.Show("Please select a value for " + item.Column.Header.Caption.ToString());
e.Cancel = true;
break;
}
There fore, i am looking for some way to validate the new row before adding to the grid and even if the validation fails, the new row should not be discarded rather it should be held in the template where it is entered.
Thanks in advance,
Parthiban Sekar
Hello ,
I could suggest you to use BeforeRowDeactivate event and to put your validation code there. So in this event you should have code like:
if (ultraGrid1.ActiveRow.IsAddRow)
foreach (UltraGridCell item in ultraGrid1.ActiveRow.Cells)
ultraGrid1.ActiveCell = item;
ultraGrid1.PerformAction(UltraGridAction.EnterEditMode);
Also if you want to prevent user to commit AddRow pressing Enter (if the validation was not passed), then you should add the following code in load event of the form in order to modify default behavior of UltraGrid for pressing Enter key when the active row is AddRow
foreach (GridKeyActionMapping key in ultraGrid1.KeyActionMappings)
if (key.KeyCode == Keys.Enter && key.ActionCode == UltraGridAction.CommitRow && key.StateRequired == (UltraGridState.AddRow| UltraGridState.RowDirty))
key.StateRequired = UltraGridState.RowDirty;
key.StateDisallowed = UltraGridState.AddRow;
Please let me know if you have any further questions.
Hristo,
Thanks for your input.
I am able to validate using "BeforeRowDeactivate" or "BeforeRowDeactivate".
What i am interested in is to retain the new row in the new template if it fails validation (If it passes, it would be added to grid as usual).
But, by using neither of the above said two events, i was not able to retain the new row which fail validation.
Regards,