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

The properties are not displayed if the class implements ICustomTypeDescriptor

2 Answers 165 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
saravanan M
Top achievements
Rank 1
saravanan M asked on 29 Sep 2011, 03:51 AM

Properties are not displayed in the propertygrid if the class implements ICustomTypeDescriptor. Why?
--

/// <summary>
    /// Interaction logic for Myobjects.xaml
    /// </summary>
    public partial class Myobjects : Page
    {
        public Myobjects()
        {
            InitializeComponent();
 
            radPropertyGrid1.AutoGeneratingPropertyDefinition += new EventHandler<Telerik.Windows.Controls.Data.PropertyGrid.AutoGeneratingPropertyDefinitionEventArgs>(radPropertyGrid1_AutoGeneratingPropertyDefinition);
             
            radPropertyGrid1.Item = new Variable();
             
        }
 
        void radPropertyGrid1_AutoGeneratingPropertyDefinition(object sender, Telerik.Windows.Controls.Data.PropertyGrid.AutoGeneratingPropertyDefinitionEventArgs e)
        {
            AttributeCollection attributes = TypeDescriptor.GetProperties(typeof(Variable))[e.PropertyDefinition.DisplayName].Attributes;
            BrowsableAttribute browsable = attributes[typeof(BrowsableAttribute)] as BrowsableAttribute;
            if (browsable != null)
            {
                e.Cancel = !browsable.Browsable;
            }
 
            //CategoryAttribute category = attributes[typeof(CategoryAttribute)] as CategoryAttribute;
            //if (category.Category == "Common")
            //{
            //   e.Cancel = false;
            //}
 
        }
    }
 
    public class Variable : ICustomTypeDescriptor,  INotifyPropertyChanged
    {
        [Browsable(false)]
        [Category("Common")]
        public int Id { get; set; }
        [Category("Common")]
        public string Name { get; set; }
 
        [XmlAttribute("mandatoryCondition")]
        [Category("Required Field")]
        public string MandatoryCondition { get; set; }
 
        [XmlAttribute("mandatoryConditionMessage")]
        [Category("Required Field")]
        public string MandatoryConditionMessage { get; set; }
 
        /// <summary>
        /// Datatype of the Variable
        /// </summary>
        private DataType dataType = DataType.String;
        [XmlAttribute("dataType")]
        [Category("Common")]
        public DataType DataType
        {
            get
            {
                return this.dataType;
            }
            set
            {
                this.dataType = value;
                NotifyPropertyChanged("DataType");
            }
        }
 
        #region ICustomTypeDescriptor Members
        public AttributeCollection GetAttributes()
        {
            return TypeDescriptor.GetAttributes(this, true);
        }
        public string GetClassName()
        {
            return TypeDescriptor.GetClassName(this, true);
        }
        public string GetComponentName()
        {
            return null;
        }
        public TypeConverter GetConverter()
        {
            return TypeDescriptor.GetConverter(this, true);
        }
        public EventDescriptor GetDefaultEvent()
        {
            return TypeDescriptor.GetDefaultEvent(this, true);
        }
        public PropertyDescriptor GetDefaultProperty()
        {
            return TypeDescriptor.GetDefaultProperty(this, true);
        }
        public object GetEditor(Type editorBaseType)
        {
            return null;
        }
        public EventDescriptorCollection GetEvents(Attribute[] attributes)
        {
            return TypeDescriptor.GetEvents(this, attributes, true);
        }
        public EventDescriptorCollection GetEvents()
        {
            return TypeDescriptor.GetEvents(this, true);
        }
        public object GetPropertyOwner(PropertyDescriptor pd)
        {
            return this;
        }
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            return this.GetProperties();
        }
 
        // Method implemented to expose mandatory field properties conditionally, depending on DataType property
        public PropertyDescriptorCollection GetProperties()
        {
            var props = new PropertyDescriptorCollection(null);
 
            foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(this, true))
            {
                if (prop.Category == "Common" && this.DataType != DataType.String)
                    continue;
                if (prop.Category == "Range" && (this.DataType != DataType.Integer && this.DataType != DataType.Float))
                    continue;
                if (prop.Category == "Required Field")
                    continue;
                props.Add(prop);
            }
 
            return props;
        }
        #endregion
 
        #region INotifyPropertyChanged Members
        public event PropertyChangedEventHandler PropertyChanged;
 
        private void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
        #endregion
    }
 
    public enum DataType
    {
        String,
        Integer,
        Float,
        Boolean,
        Date
    }



2 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 03 Oct 2011, 05:40 PM
Hi Saravanan M,

There appears to be an issue with RadPropertyGrid's ICustomTypeDescriptor support. Thank you for reporting it. I have updated your Telerik points status accordingly. We will do our best to fix it in shortest terms (1 - 2 weeks). I will notify you as soon as the issue is resolved.

All the best,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
recotech
Top achievements
Rank 1
answered on 14 Mar 2013, 04:28 PM
Is the problem resolved?
(Telerik Version: 2012.2.725.40)

I need that, but is not work.

Update: I resolved the problem. It was not by telerik. :-)
Tags
PropertyGrid
Asked by
saravanan M
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
recotech
Top achievements
Rank 1
Share this question
or