Type converters not working in RadPropertyGrid

9 posts, 1 answers
  1. Dodd
    Dodd avatar
    44 posts
    Member since:
    Dec 2012

    Posted 22 May 2013 Link to this post

    Hello,

    I implemented a type converter for RadPropertyGrid but it's not working.
    As can be seen in the attached 'winform property grid', if a line is selected then the 'linetype' cell displays the types for various lines.
    I implemented the type converter for this as the below code, but it seems RadPropertyGrid doesn't recognize it.
    Can this be fixed? And can you inform me any other fundamental limits of RadPropertyGrid compared to Winform property grid?


            [TypeConverter(typeof(LineTypeConverterNoExpand)), GlobalizedCategory("Misc"), GlobalizedDisplayName("LineType"), GlobalizedDescription("Get/Set the vdLinetype object that the vdFigure will be drawn with."), ScriptSerialize]
            public vdLineType LineType
            {
                get
                {
                    return this.mLineType;
                }
                set
                {
                    if ((this.mLineType != value) && base.RaiseOnBeforeModify("LineType", value))
                    {
                        if ((!this.Deleted && (value != null)) && value.Deleted)
                        {
                            value.Deleted = false;
                        }
                        base.AddHistory("LineType", value);
                        this.mLineType = value;
                        base.RaiseOnAfterModify("LineType");
                    }
                }
            }

    namespace VectorDraw.Professional.vdPrimaries
    {
        using System;
        using System.ComponentModel;
        using System.Globalization;
        using VectorDraw.Professional.Utilities;
        using VectorDraw.Professional.vdObjects;

        public class LineTypeConverterNoExpand : TypeConverter
        {
            public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
            {
                if (context == null)
                {
                    return false;
                }
                return ((sourceType == typeof(string)) || base.CanConvertFrom(context, sourceType));
            }

            public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
            {
                if (value is string)
                {
                    try
                    {
                        string name = (string) value;
                        vdDocument document = TypeConverterUtilities.getDocument(context);
                        object solid = null;
                        if (document != null)
                        {
                            solid = document.LineTypes.FindName(name);
                        }
                        if (solid == null)
                        {
                            solid = document.LineTypes.Solid;
                        }
                        return solid;
                    }
                    catch
                    {
                        throw new NotSupportedException("Can not convert '" + ((string) value) + "' to type LineType");
                    }
                }
                return base.ConvertFrom(context, culture, value);
            }

            public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
            {
                vdDocument document = TypeConverterUtilities.getDocument(context);
                if (document == null)
                {
                    return new TypeConverter.StandardValuesCollection(new string[0]);
                }
                return new TypeConverter.StandardValuesCollection(document.LineTypes.GetNotDeletedItemsAndVisibleOnForms());
            }

            public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
            {
                return true;
            }
        }
    }

  2. Vera
    Admin
    Vera avatar
    263 posts

    Posted 23 May 2013 Link to this post

    Hi Dodd,

    As far as I can see you are using our Q1 2013 SP. The support for TypeConverter was added with one of our Latest Internal Builds so I would suggest you to download the LIB and to give it a try.


    Let us know if you experience any problems.

    Regards,
    Vera
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Dodd
    Dodd avatar
    44 posts
    Member since:
    Dec 2012

    Posted 27 May 2013 Link to this post

    I've tried the latest internal build, but in vain.
    I've even tested a simplest converter, but it didn't work either.
    I've used 02959RadControls_for_WPF_2013_1_0520_DEV_hotfix.
    I will open a support ticket. Can you please test with it?
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 28 May 2013 Link to this post

    Hello Dodd,

    Currently, RadPropertyGrid supports TypeCovnerter for property level. So, the example you provided above with LineType property should work correctly with the internal build. 
    The code from the support ticket illustrates TypeConverter at class level which is not supported for the time being.

    Regards,
    Maya
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Dodd
    Dodd avatar
    44 posts
    Member since:
    Dec 2012

    Posted 28 May 2013 Link to this post

    Hi Maya,

    Then do you have any near future plan for supporting TypeConverter at class level? If you have specific development timeline please let me know.
    And about the TypeConverter, if I implement all the necessary TypeConverters at property level attaching TypeConverter attribute tag for each of them, then should it work properly?
  7. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 03 Jun 2013 Link to this post

    Hi Dodd,

    We will consider the implementation of TypeConverter so that it works at class level as well for the next official release (most probably the Service Pack of Q2). I will write you back in case it comes up earlier with one of our internal builds.
    Considering the second question, if you define TypeConverter for a property, its methods should be called and property grid should display them according to this conversion. 

    Regards,
    Maya
    Telerik

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. Ivan
    Ivan avatar
    43 posts
    Member since:
    Nov 2013

    Posted 18 Nov 2013 Link to this post

    Hi Maya,
    i have this problem, too. I tried to convert one my enum value to string, in order to show it in PropertiyGrid in text box instead DropDownBox.
    But i got always error, that can not convert string to IValueConverter.

    <telerik:PropertyDefinition
    Binding="{Binding MyClass.MyEnum, Converter={StaticResources myEnumToStringConverter}}"
    IsReadOnly="True"
    GroupName="Group1"
    DisplayName="Property1"
    OrderIndex="1" />
  9. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 20 Nov 2013 Link to this post

    Hello Ivan,

    IValueConverter is used for display purposes only. What you can try is to update the editor template instead:
    <telerik:PropertyDefinition Binding="{Binding Position}"                                       
                                        GroupName="Group1"
                                        DisplayName="Property1"
                                        OrderIndex="1" >
                    <telerik:PropertyDefinition.EditorTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Position}" />
                        </DataTemplate>
                    </telerik:PropertyDefinition.EditorTemplate>
                </telerik:PropertyDefinition>


    Regards,
    Maya
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  10. Ivan
    Ivan avatar
    43 posts
    Member since:
    Nov 2013

    Posted 20 Nov 2013 Link to this post

    Thanks Maya, that works.
Back to Top
UI for WPF is Visual Studio 2017 Ready