This is an urgent issue, so a quick response would be appreciated.
We are attempting to bind custom biz objects to the ultra grid and also to use the row template editor.
When binding objects with DateTime or numeric properties, we need users to be able to enter an 'empty string' in some cases, but the row template editor is having a problem with this. For example, if we use the following property and then try to remove an existing date, the template editor will not respond to the OK or Cancel buttons. If we use a datatable with the same data type, everything works fine:
Public
Property Col2() As System.DateTime
Get
Else
' Return _Col2
_Col2 = value
The RowEditTemplate uses the same editor, and constraints, that the cell would use when directly editing it, so I don't think this issue is specific to the template. Regardless, it sounds like the DataSource does not like the null value that is being passed from the grid when trying to update the cell. Try setting the Nullable property of the column to Nothing.
-Matt
Matt,
Thanks for a quick reply and sorry for the terrible formatting of my code; however, this issue may be specific to the row editor control. If I set the individual grid column's Nullable property to EmptyString, for example, and remove the row editor, I don't have any problems editing it, but when the editor is attached, it still will not respond to the OK and Cancel buttons if I attempt to remove an existing date.
I also tried setting the column's Nullable property to 'Nothing', as you suggested. In the row template, the corresponding UltraDateTime editor for that cell only has a True/False value for the Nullable property. If I set it to True, I still have the problem behavior. If I set that to False, the control injects default dates when the editor opens on an empty date - i.e. the date from the previous cell - which is not what we're looking for.
I didn't have any trouble accomplishing this using an UltraGridCellProxy; one of the possibilities that stands out here (and that the DataTable handles for you) is that the DateTime type itself is not nullable. You could certainly change this changing your class' type to DateTime? (Nullable<DateTime>) in addition to setting the Nullable property of the column. This worked both with and without the RowEditTemplate for me.
This changes, however, if you're using an UltraDateTimeEditor that is bound to the column through the RowEditTemplate (such as if you used something like "this.ultraDateTimeEditor1.DataBindings.Add(...)"). There seems to be an issue with the .NET Binding where it is trying to push DBNull.Value back into the data source, which it does not acccept. I'm not sure what is causing this, it could be a bug.
Assuming that this is the problem that you're having, the easiest solution is to use the UltraGridCellProxy instead of a standalone control. If this is not the same problem, perhaps you can attach a small sample application that I could take a look at.
Actually, for anybody having this issue, here are the steps we took:
1) You need to declare your private and public properties as nullable as shown
Private _CompletionDate As Nullable(Of System.DateTime)
Public Property CompletionDate() As Nullable(Of System.DateTime)
Return _CompletionDate
End Get
Set(ByVal value As Nullable(Of System.DateTime))
_CompletionDate = value
End Set
End Property
2) And in the Grid InitializeRow Event you need to check for null dates and set it to nothing.
Private Sub grdAssignments_InitializeRow(ByVal sender As System.Object, ….
Try
If e.Row.Cells("CompletionDate").Value = #1/1/1900# Or e.Row.Cells("CompletionDate").Value = #12:00:00 AM# Then
e.Row.Cells("CompletionDate").Value = Nothing
e.Row.Update()
End If
Catch ex As Exception
MsgBox(MyBase.LogError(ex))
End Try
End Sub
3) There are other mask properties that you need to set on the grid design for the date to show properly.
We tried converting to a nullable type and that seems to work! We've been on this issue for days and didn't think of that.
You guys and gals are a bunch of geniuses! And thank you for the quick response!