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

DateTime Column Order

5 Answers 84 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Cesar
Top achievements
Rank 1
Cesar asked on 26 Jun 2015, 11:28 AM

Hi,

In the new version of UI for WinForms (2015.2.623) I have found a bug. When I try order a DateTime Column that contains null values I get an exception. This did not happen with the previous version.

I include a link to the example of the error: https://dl.dropboxusercontent.com/u/21787064/DateTimeOrder.zip

Regards

5 Answers, 1 is accepted

Sort by
0
Ivan Petrov
Telerik team
answered on 29 Jun 2015, 08:51 AM
Hello Cesar,

Thank you for writing.

Thanks to the sample project I was able to quickly reproduce and identify the cause for the issue. In our latest version we involved the column's DateTypeConverter in the sorting process. This gives developers another means to control the sorting process. The issue here is that our RadGridDateTimeConverter doesn't know how to convert null to a valid DateTime object. I have logged this issue in our feedback portal. You can track its progress, subscribe for status change alerts and add your vote/comment to it on the following link - Feedback item.

To workaround the issue you can create a custom type converter and assign it to the date time column. Here is a code snippet that demonstrate s this. I have also attached a modified version of your sample which includes these changes.
public class CustomRadGridDateTimeConverter : RadGridDateTimeConverter
{
    public CustomRadGridDateTimeConverter(GridViewDateTimeColumn column)
        : base(column)
    { }
 
    public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
    {
        if (destinationType == typeof(DateTime) && value == null)
        {
            return DateTime.MinValue;
        }
 
        return base.ConvertTo(context, culture, value, destinationType);
    }
}
this.radGridView1.Columns["DateTime"].DataTypeConverter = new CustomRadGridDateTimeConverter(this.radGridView1.Columns["DateTime"] as GridViewDateTimeColumn);

I have updated your Telerik Points for bringing this issue to our attention.

I hope this will help. Should you have further questions, I would be glad to assist.

Regards,
Ivan Petrov
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Cesar
Top achievements
Rank 1
answered on 29 Jun 2015, 10:28 AM

Thank you very much for the answer.

Just a detail, I would change the code from:

if (destinationType == typeof(DateTime) && value == null)

to:

if (destinationType == typeof(DateTime) && (value == null || value is DBNull)

If the null comes from a database query.

Regards

0
Ivan Petrov
Telerik team
answered on 29 Jun 2015, 02:42 PM
Hi Cesar,

Thank you for your reply.

I am glad I've been able to help. You have a valid point here on the DBNull. I will make sure I include this in the workaround in the feedback item and will add it to the internal info for the issue.

Feel free to write back should you have further feedback or questions.

Regards,
Ivan Petrov
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
erwin
Top achievements
Rank 1
Veteran
Iron
answered on 10 Jul 2015, 09:25 AM
Hi, this bug seems to plague several column types - had it on Decimal columns too. The suggested workaround is not really an option for larger projects. Unfortunately a showstopper for 2015Q2.
0
Ralitsa
Telerik team
answered on 13 Jul 2015, 11:38 AM
Hi Erwin,

Thank you for your reply. 

We are aware that  the exception is thrown when a decimal column with types int, float, real, decimal or double contains null values. You can track its progress, subscribe for status changes and add your vote/comment to it on the following link: FIX. RadGridView - Sorting a column containing nulls causes an exception.

As a workaround, you can use custom TypeConverters. In the attachments, you can find a sample demo project with a backup of SQL database where the suggested workaround is implemented. If the issue is a showstopper to you, you can use this workaround until we release our service pack in the end of July. 
 
I hope this will help. Do not hesitate to write back with further questions.
 
Regards,
Ralitsa
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
GridView
Asked by
Cesar
Top achievements
Rank 1
Answers by
Ivan Petrov
Telerik team
Cesar
Top achievements
Rank 1
erwin
Top achievements
Rank 1
Veteran
Iron
Ralitsa
Telerik team
Share this question
or