This is a migrated thread and some comments may be shown as answers.

GridViewDateTimeColumn with empty/null value

8 Answers 1559 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 09 Jul 2009, 10:05 PM
I'm binding a GridView to a datasource with Date/Time fields which may be null or empty. I'd like to either display "none' or a blank string in the column, but no matter what I do it always shows up as "1/1/0001 12:00:00 AM".

How can I at least hide this text?

8 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 15 Jul 2009, 01:22 PM
Hello Robert,

The DateTimePicker editor does not support null values, this is why it displays the earliest possible date.
This functionality works as expected in the Q2 Release - please find attached a screenshot that demonstrates this.

I would suggest upgrading to our latest Q2 release. It includes several major improvements in the framework on which RadControls are based. The most important changes are a refactored RadObject which implements a more efficient property storage and retrieval mechanism which improves both performance and memory usage. In addition, you will find a completely new RadDock control which is more lightweight and flexible than the previous DockingManager.
 

Sincerely yours,
Victor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Tom
Top achievements
Rank 1
answered on 30 Mar 2010, 05:04 PM
I'm still having this problem even with new release of q1 2010.  When the date field is retrieved from the database and it is empty, grid control automatically enters 1/1/0001 for it in the field.
0
Deyan
Telerik team
answered on 02 Apr 2010, 02:32 PM
Hello Tom,

 Thanks for writing.

I have tried to reproduce the case using the Q1 2010 DLLs but it works as expected on my side, i.e. I have bound my grid to a data table containing rows with Date Time fields and I get empty cells each time the Date Time field is NULL in the database.

Could you please confirm that you are using Q1 2010? I would also like to ask you to prepare a small WinForms application that demonstrates the issue so that we can directly take a look at it.

Please note that you will have to open a new support ticket in order to be able to attach your project.

Thanks for your time.

Regards,
Deyan
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
David
Top achievements
Rank 1
answered on 23 Apr 2012, 08:33 PM
I have Q1 2011 and null datetime values in gridViewDateTimeColumn1 still want to display as 1/1/0001.  I have to display an empty date time field.  How is this accomplished?
0
Don
Top achievements
Rank 1
answered on 24 Apr 2012, 11:37 PM
What I've done is check the date value of the data and replaced dates of #12:00:00 AM# or #1/1/0001# with empty strings in the data set used to populate a grid. It was the only way I could get an empty cell in a date column. It's not pretty, but it works.
0
Svett
Telerik team
answered on 26 Apr 2012, 03:06 PM
Hello David,

As an alternative you can use the NullValue property of the GridViewDateTimeColumn. You can read more about this matter in the online documentation.

Kind regards,
Svett
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
David
Top achievements
Rank 1
answered on 26 Apr 2012, 03:57 PM

Note that the value of the NullValue property should be the same as its column data type. 

Using NullValue = null did not work for a null value on the DateTime column.  Nor did the attempt to chance NullValue = 0, which caused the expected error.  The NullValue = null only shows '01-01-0001' which is System.DateTime.MinValue

I had to add the following to radGridView1_CellFormatting event handler which I found elsewhere on the Telerik site.

GridViewDataColumn dataColumn = e.CellElement.ColumnInfo as GridViewDataColumn;
 
if (dataColumn.Name == "MyDateTime")
{
    DateTime dtValue = (DateTime)e.CellElement.RowInfo.Cells[dataColumn.Name].Value;
    if (dtValue == System.DateTime.MinValue)
    {
        e.CellElement.Text = "";
    }
}
0
Svett
Telerik team
answered on 30 Apr 2012, 01:47 PM
Hello David,

This approach is good as well. Still, in order to use the best practices, you can use the following version:

GridViewDataColumn dataColumn = e.CellElement.ColumnInfo as GridViewDataColumn;
 
if (dataColumn.Name == "MyDateTime")
{
    DateTime dtValue = (DateTime)e.CellElement.RowInfo.Cells[dataColumn.Name].Value;
 
    if (dtValue == System.DateTime.MinValue)
    {
        e.CellElement.Text = "";
    }
    else
    {
        e.CellElement.ResetValue(LightVisualElement.TextProperty, ValueResetFlags.Local);
    }
}
else
{
    e.CellElement.ResetValue(LightVisualElement.TextProperty, ValueResetFlags.Local);
}

I hope this helps.

Greetings,
Svett
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
GridView
Asked by
Robert
Top achievements
Rank 1
Answers by
Victor
Telerik team
Tom
Top achievements
Rank 1
Deyan
Telerik team
David
Top achievements
Rank 1
Don
Top achievements
Rank 1
Svett
Telerik team
Share this question
or