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
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.
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?
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
Perhaps I didn't understand what you're trying to do. My first impression was that you want to perform some custom validation and cancel the ExitingEditMode event if validation fails. In addition, pressing the Escape key would cancel the whole add new row operation. So, this can be achieved by examining the value of EditingCancelled argument and perform the validation only if the operation wasn't cancelled (EditingCancelled = false).
However, I didn't see that you already perform this check in your code, so this is why I removed my previous post. I assumed that this is not what you're looking for. Could you describe the behavior you're trying to achieve in more detail?
Thanks,
Well, to the reply which was deleted, if you look at my code, I am doing exactly that on line 125. I tried setting e.editingcanceled myself if a condition is raised, but it is a readonly property (at least in 2009.2)