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

DateTimePicker in GridView

6 Answers 103 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sandi Markon
Top achievements
Rank 1
Sandi Markon asked on 10 Mar 2011, 03:18 PM
When setting day bigger than 12, following error occours:
14.3.2011 0:00:00 is not a valid value for DateTime.
I have tried to set FormatString to {0:dd/MM/yyyy}, then FormatInfo to sl-SI and then both, but nothing works. Windows regional settings are set to Slovenian.

6 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 14 Mar 2011, 12:36 PM
Hello Sandi,

Please try the following:
On DataBindingComplete event, go through all of the columns, and if the column type is GridViewDateTimeColumn just set the FormatInfo to CultureInfo.CurrentUICulture and the FormatString to {0:d};

like so:

void radGridView_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
{
    var grid = sender as RadGridView;
    foreach (var column in grid.Columns)
    {
        if (column is GridViewDateTimeColumn)
        {
            column.FormatInfo = CultureInfo.CurrentUICulture;
            column.FormatString = "{0:d}";
        }
    }
}

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP

0
Sandi Markon
Top achievements
Rank 1
answered on 14 Mar 2011, 04:06 PM
I have tried, but with no success. I have set datasource to custom object that is not bound to database. It works ok even without setting any FormatInfo or FormatString. But when I set datasource to Linq object, error occours before any data is sent to SQL server.
0
Emanuel Varga
Top achievements
Rank 1
answered on 14 Mar 2011, 04:20 PM
Hello again,

Can you please put together a small example illustrating this problem?

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Sandi Markon
Top achievements
Rank 1
answered on 15 Mar 2011, 09:23 AM
I made a small example which you can download here:
http://www.mjnet.si/Telerik_DateTime.zip
0
Emanuel Varga
Top achievements
Rank 1
answered on 15 Mar 2011, 12:09 PM
Hello Sandi,

This is not a telerik issue,

Please try also adding a windows DataGrid and change the date manually, it will throw a similar exception, so i'm betting is has something to do with the DataContext.

I'll let you know when i find a solution to this.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
Telerik WinForms MVP
0
Stefan
Telerik team
answered on 16 Mar 2011, 10:26 AM
Hi guys, 

Thank you for writing.

There was a known issue in the previous release with the conversion layer of RadGridView. This issue will be addressed in the upcoming Q1 2011 release which is due in the end of the current week. Please download this version once it is released and test your scenario again. In my tests everything works as expected.

If you still experience this issue, do not hesitate to write back.

Best wishes,
Stefan
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
GridView
Asked by
Sandi Markon
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Sandi Markon
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or