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

RadDateTimeEditor defaults to 1 Jan 1753

14 Answers 134 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Johan
Top achievements
Rank 1
Johan asked on 29 Jan 2011, 06:27 PM
Hi,

Any idea why my RadDateTimeEditor columns always defaults to 1 Jan 1753 on selection?

I've looked at the properties that RadDateTimeEditor expose but can find anything relevant.

Is there a why to default it to DateTime.Now maybe?

Thanks

14 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 29 Jan 2011, 06:38 PM
Hello,

Can you share the version you are using and your code? If for example you add the following to a new project with just a RadGridView on the page

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Me.RadGridView1.Columns.Add(New GridViewTextBoxColumn("A"))
    Me.RadGridView1.Columns.Add(New GridViewTextBoxColumn("B"))
    Me.RadGridView1.Columns.Add(New GridViewDateTimeColumn("C"))
    Me.RadGridView1.Rows.Add("A1", "B1", Nothing)
    Me.RadGridView1.Rows.Add("A2", "B2", Nothing)
    Me.RadGridView1.Rows.Add("A2", "B2", Nothing)
End Sub

then the date defaults to today when the cell is in edit mode and you drop down the calendar. The cell value is currently Null.
Regards,
Richard
0
Johan
Top achievements
Rank 1
answered on 29 Jan 2011, 07:09 PM
Hi,

I'm using version 2010.2.10.914 of the winform controls.

Here is my code:

GridViewDateTimeColumn col = new GridViewDateTimeColumn();
 
col.Name = node.Name;
col.FieldName = node.Name;
col.HeaderText = friendlyName;
col.FormatString = "{0:yyyy-MM-dd}";
col.Width = 150;
 
radGridView1.Columns.Add(col).

Hope this helps?
0
Richard Slade
Top achievements
Rank 2
answered on 29 Jan 2011, 08:51 PM
Hi Ryno,

As we are using different versions, I want to ensure I know how you are populating the grid. Please could you also let me know this as it may affect the answer.
Thanks
Richard
0
Johan
Top achievements
Rank 1
answered on 30 Jan 2011, 09:30 AM
Hi,

My grid datasource is coming from a dataset which I load from excel.

Here is the code:

DataSet dsData = new DataSet();
 
dsData.ReadXml("XMLFile.xml");
radGridView1.DataSource = dsData.Tables[0];

Thanks
0
Richard Slade
Top achievements
Rank 2
answered on 30 Jan 2011, 11:04 AM
Hello,

If you set the value to null, this shouldn't happen. The date will be today, however, if the date is defined as
new DateTime();
then it seems the editor will always show 1753. At the moment, I haven't been able to change the date, despite setting the value of the RadDateTimeEditor when the CellEditorInitualized event is fired.

I'll keep having a look for you as I'm sure this should be straightforward and let you know if i can get it for you.
regards,
Richard
0
Johan
Top achievements
Rank 1
answered on 30 Jan 2011, 12:14 PM
Thanks Richard!

Its really odd that this is happening... 
0
Richard Slade
Top achievements
Rank 2
answered on 30 Jan 2011, 12:21 PM
Hello Ryno,

You can set the columns Null value by using
Column.NullValue = DateTime.Today;
but if your data has a date, and that date is
DateTime date = new DateTime();
then this date is not null, so it will display that value. The editor is displaying the value of the cell, which I think is normal. In this case I beleive you would need to set a default date in your data source. If you want the date to be today, then set the date to null, and set the null value for the column

Hope that helps
Richard
0
Johan
Top achievements
Rank 1
answered on 30 Jan 2011, 12:55 PM
Thanks for this Richard.

The challenge I'm facing now is that datasource (DataSet) gets populate from XML via ReadXml(). At that point all the DataColumns in the DataTable is of type string and I can't change the data type once the DataTable is filled with data.

Again, thanks. You have been of great help.
0
Richard Slade
Top achievements
Rank 2
answered on 30 Jan 2011, 01:08 PM
Hi. If you'd like to post a sample project I'll see what I can do with it. Richard
0
Richard Slade
Top achievements
Rank 2
answered on 30 Jan 2011, 04:13 PM
Ryno,

If the type is coming out as string, then you could make the column in your data table null(able)?
regards,
Richard
0
Johan
Top achievements
Rank 1
answered on 30 Jan 2011, 07:30 PM
Hi Richard,

I'm not sure I understand you correctly. What do you mean by making it nullable?

My columns in the datatable gets created dynamically when I read xml into the dataset and therefore I don't have control to change any of the data columns. I hope I make sense?! :-)
0
Richard Slade
Top achievements
Rank 2
answered on 30 Jan 2011, 07:50 PM
Ok,

If you had control of the datatable then if the column is nullable, then you are able to control a null date. There must be blank dates (minimum dates) in your data therefore.
Richard
0
Stefan
Telerik team
answered on 03 Feb 2011, 12:22 PM
Hello guys,

Thank you both for writing.

Let me check if I have understood correctly:
You have a xml that comes from Excel and then you load it in a DataSet which is the DataSource for RadGridView. When the source is loaded, it is displayed in RadGridView as the MinDate (1 Jan 1753) and you want to show the today date.

Since you can not access the data set, the other approach is to iterate over the cells and change the values of the desired cells after you bind the grid. To do that, subscribe to the DataBindingComplete event of RadGridView and use the following code snippet:
void radGridView1_DataBindingComplete(object sender, Telerik.WinControls.UI.GridViewBindingCompleteEventArgs e)
       {
           foreach (GridViewRowInfo rowInfo in radGridView1.Rows)
           {
               foreach (GridViewCellInfo cellInfo in rowInfo.Cells)
               {
                   if ((cellInfo.ColumnInfo.Name == "DateTime"))
                   {
                       if (cellInfo.Value.Equals(new DateTime()))
                       {
                           cellInfo.Value = DateTime.Now;
                       }
                   }
               }
           }
       }

Let me know if this works for you. 
 
All the best,
Stefan
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
0
Johan
Top achievements
Rank 1
answered on 07 Feb 2011, 05:58 PM
Hi guys

Sorry for only providing you with some feedback now...

Anyway, after a lot of investigation and debugging it was clear that something was wrong somewhere else and not necessarily at the point where I create and setting the column's formats etc.

As it turns out my problem was at the point where I set the grid's data source, in my case the DataTable. All my data from the XML which I loaded in the dataset was of type String...

The approach I took was to create the DataTable programmatically by setting each column to the correct data type first and then only load the XML into the DataTable.

DataTable tbl = new DataTable("MyTable");
 
tbl.Columns.Add("tb_BarCode", typeof(String));
tbl.Columns.Add("dt_PurchaseDate", typeof(DateTime));
 
tbl.ReadXml(myXMLFile);

Obviously you need to make sure that the XML is in the correct format. What I did was to create the DataTable as per above example, set the columns and added some some data and then wrote the DataTable to XML to see what the correct format should look like.

By correcting the format and types of my grid's datasource (the DataTable) solved pretty much all my issues I had with formatting etc.

Regards  
Tags
GridView
Asked by
Johan
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Johan
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or