Geeks With Blogs
David Madden Mastering the craft one mountain at a time.
For whatever reason of which the Fates may only know, we experienced a difference in pulling data manually as a list of objects than we did in pulling a list of objects from an entity framework.  The current work around to get an empty value in the null datetime field was to do the following in the RadGridView's CellFormatting event.  We are using RadControls for Winforms 2011 Q1.

Oddly enough, as mentioned above, pulling the data as a list of objects from an entity framework does not have to have this work around.  We tried having DateTime? MyDateField in the field list of the object without the code below.  It would display '01/01/0001' for each null value in the DateTime column of the grid.

So the measure below is in place.  It is very quick and does not cause a lot of overhead.  Still I would prefer a better solution if someone has fought this before.

private void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
   if (e.CellElement != null)
      GridViewDataColumn dataColumn = e.CellElement.ColumnInfo as GridViewDataColumn;
      if (dataColumn.Name == "MyDateField")
         DateTime dtValue = (DateTime)e.CellElement.RowInfo.Cells[dataColumn.Name].Value;
         if (dtValue == System.DateTime.MinValue)
            e.CellElement.Text = "";
Posted on Tuesday, April 24, 2012 1:23 PM | Back to top

Comments on this post: One way to have Telerik RadGridView control show blank value for a null value in DateTime column

# re: One way to have Telerik RadGridView control show blank value for a null value in DateTime column
Requesting Gravatar...
Before even reading your post in full I'd assumed setting value to empty string would do the trick. This seems to be their de facto method for dealing with anything where a value, or even records in datasource, is not present.

I have not used the WinForms version of their RadControls, but having used the ASP.NET RadControls one had to follow the same rules.

Anyway, nice catch!
Left by Jake Rutherford on Apr 24, 2012 10:33 PM

Your comment:
 (will show your gravatar)

Copyright © DavidMadden | Powered by: