I have an ultragrid with one of the columns having a valuelist of all employees. I set the column style to DropDownValidate (since I want AutoComplete but do not want the user to add values that aren't in the list). I wanted to capture the CellDataError event and put my own messagebox instead of the generic one, but I noticed that the event fires multiple times for one error, thereby displaying multiple error messageboxes in a row.
Do you know why this would be happening and how to prevent it so that it is only called once?
Thank you for your assistance, ~Kelly
Hi Kelly,
I am not aware of any reason why the evert would fire twice, unless there are two errors. Can you duplicate this behavior in a small sample project? What kind of error are you getting? What are you doing in the Error and/or CellDataError events of the grid?
Hi Mike,
Is there a way to do it by skipping the CellDataError event altogether and just somehow passing it to my ErrorProvider (which I set through DataTable_OnRowChanging).
Thanks!~Kelly
I wonder if the MessageBox is somehow throwing off the timing. Try taking that out - maybe just put in a Debug.Writeline or Console.WriteLine instead and see if the event still fires multiple times. If that solves the issue, the perhaps you need to display the MessageBox using a BeginInvoke rather than directly inside the CellDataError event. I find it odd that the CellDataError event doesn't have a param to cancel the default error message. I assume this is because the error message isn't displayed until the Error event. So maybe that's where you need to display your MessageBox, too.
If you want to show errors without a messagebox, then the only support for that in the grid is the UseDataErrorInfo property, which picks up data errors from the DataTable's IDataErrorInfo implementation.
I tried Console.Writeline and it still fired 2x. If I utilize the UseDataErrorInfo property, how do I feed that to my error provider, and during which event?
Thank you for your help! ~Kelly
Forgot to mention that you reset the ErrorCounter variable in the grid's KeyDown event:
Private Sub Grid_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Grid.KeyDown Me.ErrorCounter = 0End Sub
Hope This Helps!~Kelly
Here is an update if anyone else is having the same issue. I worked with Saurabh from Dev. Support on this issue and discovered that it had to do with altering the grid's default KeyActionMappings. I changed them to allow enter/return to commit the row as follows:
Private Sub MakeEnterCommitTheRow(ByVal Grid As UltraGrid) ' create a new mapping for a key in the specified grid Dim NewKeyActionMapping As GridKeyActionMapping For Each MyKeyActionMapping As GridKeyActionMapping In Grid.KeyActionMappings ' for each of the key mappings in the specified grid If MyKeyActionMapping.KeyCode = Keys.Enter Or MyKeyActionMapping.KeyCode = Keys.Return Then ' if it is for the enter or return key, delete the mapping MyKeyActionMapping.Dispose() End If Next ' add a new mapping for the enter key that will commit the row in the grid NewKeyActionMapping = New GridKeyActionMapping(Keys.Enter, UltraGridAction.CommitRow, 0, UltraGridState.Cell, Infragistics.Win.SpecialKeys.All, 0) Grid.KeyActionMappings.Add(NewKeyActionMapping) ' add a new mapping for the return key that will commit the row in the grid NewKeyActionMapping = New GridKeyActionMapping(Keys.Return, UltraGridAction.CommitRow, 0, UltraGridState.Cell, Infragistics.Win.SpecialKeys.All, 0) Grid.KeyActionMappings.Add(NewKeyActionMapping)End Sub
Since I need enter to commit the row, but it was causing the error, we came up with a workaround. Declare a counter: Dim ErrorCounter As Integer = 0Then, use that counter in the grid's Error event (do not use the CellDataError event):
Dim ErrorCounter As Integer = 0
Private Sub Grid_Error(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.ErrorEventArgs) Handles Grid.Error If ErrorCounter = 0 Then ' if it is the first time it is called If e.DataErrorInfo.Cell.Text <> "" Then ' and the cell isn't null (since we allow nulls) e.ErrorText = "Message Here" ' display the error message ErrorCounter = 1 ' set the counter to 1 so it doesn't display the message multiple times Else ' cell is null (if you want to allow nulls) e.Cancel = True ' cancel the error e.DataErrorInfo.Cell.Value = "" ' set the cell value to null End If Else ' error being called again (not supposed to happen) e.Cancel = True ' cancel the error End IfEnd Sub
I made a small sample application and it only fired once when I clicked out of the row; however, when I assign Enter the KeyActionMapping of CommitRow, it fires multiple times
I also submited an incident to developer support as you suggested (sample app attached to this post).
Where do I look to see what hotfix version we are using?
For now, I will just make it so they cannot leave the cell until they choose an item from the list.
Kelly said:I tried Console.Writeline and it still fired 2x.
Okay, then that's most likely a bug. Are you using the latest Hot Fix? If not, you should get it and see if it helps. If it doesn't, then you will need to Submit an incident to Infragistics Developer Support so they can check this out and get it resolved.
Kelly said:If I utilize the UseDataErrorInfo property, how do I feed that to my error provider, and during which event?
The DataErrorInfo has to come from the data source. So I'm not sure this will work for what you need, and to be honest, I'm not really an expert on how it works. There are methods on the DataTable for setting the error on a row or cell. I'm not sure what event you would use, and I suspect this would probably entail more work than should be neccessary here. Your best bet is probably reporting the issue to Infragistics and letting them get it fixed.