DateTime Column Order

6 posts, 0 answers
  1. Cesar
    Cesar avatar
    21 posts
    Member since:
    Oct 2012

    Posted 26 Jun 2015 Link to this post

    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

  2. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 29 Jun 2015 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Cesar
    Cesar avatar
    21 posts
    Member since:
    Oct 2012

    Posted 29 Jun 2015 in reply to Ivan Petrov Link to this post

    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

  5. Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 29 Jun 2015 Link to this post

    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
  6. erwin
    erwin avatar
    358 posts
    Member since:
    Dec 2006

    Posted 10 Jul 2015 in reply to Ivan Petrov Link to this post

    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.
  7. Ralitsa
    Admin
    Ralitsa avatar
    176 posts

    Posted 13 Jul 2015 Link to this post

    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready