I have a grid with AllowAddNewRow set to bottom. I am processing the RowExitingEditMode event to do data validation, canceling the event if validation fails. However, I need a way to allow the user to just 'nevermind' the whole add row scenario.
What I was thinking of was like an escape functionality, such as the escape key would just erase the input up until that point. Any hints on how to wire this up?
Here is an example snippet of what happens on validation..
117 Private Sub dgpro_RowExitingEditMode(ByVal sender As Object, _
118 ByVal e As Infragistics.Silverlight.ExitEditingRowEventArgs) _
119 Handles dgpro.RowExitingEditMode
120
121 Dim data As PTProject = e.Row.Data()
122
123 Me._blnAddEventCancelled = False
124
125 If Not e.EditingCanceled Then
126
127 If data.Company Is Nothing OrElse data.Company = String.Empty Then
128
129 MessageBox.Show("Please Enter Company.", "Proliance Mapping", MessageBoxButton.OK)
130
131 e.Cancel = True
132
133 Me._blnAddEventCancelled = True
134
135 Else
Hi Alan,
Try something like: if (e.Row.RowType == RowType.AddNewRow) {
if (!e.EditingCanceled) {
e.Cancel = true;
this.grid.ExitEditMode(true);
}
Hope this helps,
-SteveZ
The problem with that approach is that even though I issue an e.cancel and ExitEditMode, it keeps on throwing the RowExitingEditMode event in a loop because this validation is happening in the RowExitingEditMode event.
Maybe the event model is wrong. If you wanted to do validation on rows being added to your grid, would you choose to implement your validation in a different event than RowExitingEditMode?
I figured out a better event model to work with. Basically do validation in the cellexitingeditmode event, setting a boolean on input errors, and using that boolean to trigger cancellation on rowadding event, and basing updates on rowexitingedit mode and that boolean being false. Also initialize it to false when entering row edit mode and triggering the cancellation on navigationfrom events on the page. Whew.