EntitySpaces Version # 2007.0.0730.0
MyGeneration Version # 1.2.0.7
Language: VB.NET
Using the Infragistics WinGrid with EntitySpaces leads sometimes to let's say interesting issues. Using VB.NET does the rest...
Bounding an EntityCollection to WinGrid and deleting the value of a cell, results in a DBNull-Value for that cell. Since in VB we need the value Nothing, you get permanent errors like "Unable to update the data value: The object with the type System.DBNull can not be converted to the type System.String.". (I've tried to translate the message...)
To get around this issue, you have to switch DBNull into Nothing.
Code:
Private _DBNullToNothingCell As UltraGridCell = Nothing
Private Sub uxGrid_BeforeCellUpdate(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.BeforeCellUpdateEventArgs) Handles uxGrid.BeforeCellUpdate
If IsDBNull(e.NewValue) Then _DBNullToNothingCell = e.Cell
End Sub
Private Sub uxGrid_CellDataError(ByVal sender As Object, ByVal e As Infragistics.Win.UltraWinGrid.CellDataErrorEventArgs) Handles uxGrid.CellDataError
If _DBNullToNothingCell IsNot Nothing Then
e.RaiseErrorEvent = False
e.RestoreOriginalValue = False
e.StayInEditMode = False
_DBNullToNothingCell.Value = Nothing
_DBNullToNothingCell = Nothing
End If
End Sub
The reason why I use the variable DBNullToNothingCell and not ActiveCell in CellDataError is, that in some circumstances ActiveCell ist not always the same. Furthermore it is not possible to change the value of the cell in BeforeCellUpdate. That's why I'm doing it in the CellDataError-Event.
I'm sure there is a more elegant solution out there, and I'm definitly interested in it. Maybe I've missed something in ES, so that I could avoid using these events. But on the other hand, if some else is just struggling with this issue, here are my 2 Cents how you can deal with it.
BTW, I've just started using EntitySpaces again for a current project - after using it on the same project about one year ago. I really have to say that it is a lot of fun working with it again. I think you - the ES Team - are really doing a great job.
Thanks for a great product!