Completed
Last Updated: 13 Dec 2017 13:42 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 23 Aug 2017 09:30
Category: GridView
Type: Bug Report
1
FIX. RadGridView - FormatException when using a TypeConverter for GridViewCheckBoxColumn with EnableHeaderCheckBox property set to true
To reproduce:

1. Add a GridViewCheckBoxColumn with EnableHeaderCheckBox property set to true.
2. Use the TypeConverter demonstrated in the following help article: http://docs.telerik.com/devtools/winforms/gridview/columns/converting-data-types

When you run the application and try to toggle the check box in the header cell, a FormatException occurs. 

Workaround: modify the TypeConverter:

public class ToggleStateConverter : TypeConverter
{
    public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
    {
        return destinationType == typeof(ToggleState);
    }

    public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
    {
        char charValue = (char)value;

        switch (charValue)
        {
            case 'Y':
                return ToggleState.On;
            case 'N':
                return ToggleState.Off;
            case 'M':
                return ToggleState.Indeterminate;
        }

        return base.ConvertTo(context, culture, value, destinationType);
    }

    public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
    {
        return sourceType == typeof(ToggleState) || sourceType == typeof(bool);
    }

    public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
    {
        ToggleState state;
        bool boolValue;

        if (value is ToggleState)
        {
            state = (ToggleState)value ; 
            switch (state)
            {
                case ToggleState.On:
                    return 'Y';
                case ToggleState.Off:
                    return 'N';
                case ToggleState.Indeterminate:
                    return 'M';
            }
        }
        else if (value is bool)
        {
            boolValue = (bool)value;
             switch (boolValue)
            {
                case true:
                    return 'Y';
                case false:
                    return 'N';
                default:
                    return 'M';
            }
        }
       
        return base.ConvertFrom(context, culture, value);
    }
}
0 comments