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
Hi,
If you are binding to a DataSet and the field allows DBNull, then clearing out the cell in the grid should work.
Are you sure the exception you are seeing is not a FirstChanceException that the grid is already catching and handling? You might only be seeing the exception because you have your Visual Studio IDE set to break on all exceptions.
I tested this out binding the grid to a DataTable with a DateTime field that allows DBNull and it works just fine for me. I have attached my sample here so you can take a look.
I am just using DataSet returning from the function. What can I do then??
this.ugdRMA.DataSource =StaticUtil.GetDataset_RMAItems(this.RMAList, false);
public static DS_RMAItems GetDataset_RMAItems(StoreServer.VO.Item.ItemReturnedInventoryListVO rmaList, bool hist) { DS_RMAItems crDS = new DS_RMAItems(); DS_RMAItems.DT_RMA_ITEMSRow dr;
........................
If you are getting an exception when setting the cell value to null, it's most likely because the DataSource you are binding to the grid does not allow nulls for that field.
What kind of data source are you using?