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

Type converters not working in RadPropertyGrid

8 Answers 284 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Dodd
Top achievements
Rank 1
Dodd asked on 23 May 2013, 02:48 AM
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;
        }
    }
}

8 Answers, 1 is accepted

Sort by
0
Vera
Telerik team
answered on 23 May 2013, 03:22 PM
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.

0
Dodd
Top achievements
Rank 1
answered on 27 May 2013, 10:09 AM
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?
0
Maya
Telerik team
answered on 28 May 2013, 11:07 AM
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.

0
Dodd
Top achievements
Rank 1
answered on 29 May 2013, 01:22 AM
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?
0
Accepted
Maya
Telerik team
answered on 03 Jun 2013, 06:53 AM
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.

0
Ivan
Top achievements
Rank 1
answered on 18 Nov 2013, 09:48 AM
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" />
0
Maya
Telerik team
answered on 20 Nov 2013, 11:09 AM
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 >>
0
Ivan
Top achievements
Rank 1
answered on 20 Nov 2013, 11:30 AM
Thanks Maya, that works.
Tags
PropertyGrid
Asked by
Dodd
Top achievements
Rank 1
Answers by
Vera
Telerik team
Dodd
Top achievements
Rank 1
Maya
Telerik team
Ivan
Top achievements
Rank 1
Share this question
or