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,
Hello,
I have modify my sample to work with Visual Studio 2008, now you should be able to run and test the sample.
I really appreciate your efforts to help me.
To replicate what i am facing, please do the following changes.
1. Add a combo below the grid ( or wherever but away from the grid panel )
2. Now run the app, start editing the new row template but dont enter all fields , now click on the drop down (outside grid panel).
For me the validation did not happen and row got added to the grid.
The modified sln is attached.
Hristo, Could you help me out :)
Thanks
I have modify my sample based on your requirements, please run the sample and let me know if this is what you are looking for.
Thank you for using Infragistics Components.
Thanks Hristo,
Thats what i exactly need!
I just need one more thing.
In my grid, when i press "Enter" key, no action or event occurs as of now but it happens in your sample.
Could you tell me what i need to do to enable Row adding on pressing ENTER?
Thanks,
Sorry, Figured that ENTER key issue out. Thanks again,