PropertyGrid DropDownListEditor using a collection as datasource instead of standar values

1 Answer 33 Views
PropertyGrid
Marco
Top achievements
Rank 2
Veteran
Marco asked on 23 Nov 2021, 04:47 PM

Hello Telerik,

What is the simple way to use a "classic" DropDown Editor for the PropertyGrid without implementing a converter and the standar value but directly a datasource for the property of an object representing a relation to a collection !

Is it possible to change the items of the PropertyGridDropDownListEditor with event or should I implement a custom editor ?

I haven't seen this case covered in the doc.

Best regards

Marco Guignard

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Nov 2021, 02:45 PM
Hello, Marco, 

By default, RadPropertyGrid generates a PropertyGridDropDownListEditor for items which TypeConverter returns that the object supports a standard set of values that can be picked from a list, using the specified context. For example if the property type is enum: 
        public RadForm1()
        {
            InitializeComponent();

            this.radPropertyGrid1.SelectedObject= new Item(123,"Telerik", DeliveryType.Delivery);
        }

        public class Item
        {
            public int Id { get; set; }

            public string Title { get; set; }

            public DeliveryType DeliveryMethod { get; set; }

            public Item(int id, string title, DeliveryType deliveryMethod)
            {
                this.Id = id;
                this.Title = title;
                this.DeliveryMethod = deliveryMethod;
            }
        }

        public enum DeliveryType
        { 
            PickUp,
            Delivery
        }

 

Another approach is to handle the EditorRequired event and specify the editor for this particular field: 

        private void radPropertyGrid1_EditorRequired(object sender, PropertyGridEditorRequiredEventArgs e)
        {
            if (e.Item.Label == "Title")
            {
                PropertyGridDropDownListEditor editor = new PropertyGridDropDownListEditor();
                BaseDropDownListEditorElement element = editor.EditorElement as BaseDropDownListEditorElement;
                element.DataSource = new List<string>() { "WinForms", "WPF", "Reporting" };
                e.Editor = editor;
            }
        }

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Marco
Top achievements
Rank 2
Veteran
commented on 24 Nov 2021, 04:24 PM

The second approach is exactly what I was looking about !

Thank you Dess

Tags
PropertyGrid
Asked by
Marco
Top achievements
Rank 2
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or