Dear all,
In the ultragrid1, there is a datetime field named as "EXPIRY_DATE". How to make it show as empty when it is null or it is DateTime.MinDateTime. I am trying to assign null value to it, but it throw exception. Is there any other method without amending the datetime field to be string??
private void ultragrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e) { if (Convert.ToDateTime(e.Row.Cells["EXPIRY_DATE"].Value) == DateTime.MinValue) e.Row.Cells["EXPIRY_DATE"].Value = null; // it throws exception that cannot convert }
This might (or might not) help. Similarly, I have a UltraWinGrid whose DataSource is a DataSet with defined DataTables which contain DataColumns that are of the System.DateTime type (which is not nullable). The data for the DataTime field when not set in the underlying MS SQL database is #12:00:00:00 AM# which displays in the DateTime column in the UltraWinGrid as "01/01/0001".
This date looks strange and I wanted it to either display "(none)" or simply display nothing (blank).
I set the Column NullText property:
Dim UltraGridColumn1 As Infragistics.Win.UltraWinGrid.UltraGridColumn = _ New Infragistics.Win.UltraWinGrid.UltraGridColumn("SomeDateTime")
UltraGridColumn1.NullText = "(none)" - or - UltraGridColumn1.NullText = " "
Then, in the InitializeRow event for the grid, I check the value of the DateTime field for the #12:00:00 AM# value and reset the vale to DBNull.Value.
Private Sub ultraWinGrid1_InitializeRow(sender As Object, _ e As Infragistics.Win.UltraWinGrid.InitializeRowEventArgs) _ Handles ultraWinGrid1.InitializeRow
If (IsDBNull(e.Row.Cells("SomeDateTime").Value) = False) _ AndAlso (Year(e.Row.Cells("SomeDateTime").Value) = 1) Then
e.Row.Cells("SomeDateTime").Value = DBNull.Value
End If
End Sub 'ultraWinGrid1_InitializeRow