DropDownList in RadPropertyGrid does not trigger PropertyValueChange event after Value is changed by user

1 Answer 198 Views
DropDownList PropertyGrid
Guillaume
Top achievements
Rank 1
Guillaume asked on 28 Jan 2022, 07:00 PM

I have a PropertyGrid with 2 types of editors ; SpinEditor and DropDownListEditor. After the user changes a value in a SpinEditor, it triggers the event PropertyValueChange. However, after the user selects a new value in the DropDownListEditor, it does not trigger the PropertyValueChange. The ValueChanged event is fired but the new data is not saved in the item at this point. 

How can I make it trigger the PropertyValueChange event after the user changes the value in the DropDownList?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 01 Feb 2022, 12:37 PM
Hello, Guillaume,   

I would like to note that while an item in RadPropertyGrid is in edit mode, any value changes are reflected to the editor itself. However, this value is not expected to be applied to the associated property item until the editor's value is committed either by pressing Enter or by navigating to another property item. 

If you want to update the value immediately after selecting a new item in the PropertyGridDropDownListEditor, I would suggest you to use the following code snippet:
        public RadForm1()
        {
            InitializeComponent();

            Item item = new Item(123, "Title", DelivertType.PickUp);
            this.radPropertyGrid1.SelectedObject = item;

            this.radPropertyGrid1.PropertyValueChanged += radPropertyGrid1_PropertyValueChanged;

            this.radPropertyGrid1.EditorInitialized += radPropertyGrid1_EditorInitialized;
        }

        private void radPropertyGrid1_EditorInitialized(object sender, PropertyGridItemEditorInitializedEventArgs e)
        {
            PropertyGridDropDownListEditor ddlEditor = e.Editor as PropertyGridDropDownListEditor;
            if (ddlEditor != null)
            {
                BaseDropDownListEditorElement element = ddlEditor.EditorElement as BaseDropDownListEditorElement;
                element.SelectedIndexChanged -= element_SelectedIndexChanged; 
                element.SelectedIndexChanged += element_SelectedIndexChanged; 
            }
        }
         
        private void element_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
        {
            BaseDropDownListEditorElement element = sender as BaseDropDownListEditorElement;
            element.SelectedIndexChanged -= element_SelectedIndexChanged; 
            this.radPropertyGrid1.EndEdit();
        }

        private void radPropertyGrid1_PropertyValueChanged(object sender, PropertyGridItemValueChangedEventArgs e)
        {
            this.Text = e.Item.Label;
        }

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

            public string Title { get; set; }

            public DelivertType Delivery { get; set; }

            public Item(int id, string title, DelivertType delivery)
            {
                this.Id = id;
                this.Title = title;
                this.Delivery = delivery;
            }
        }

        public enum DelivertType
        { 
            PickUp,
            Delivery
        }

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/.

Guillaume
Top achievements
Rank 1
commented on 02 Feb 2022, 07:31 PM

Thanks. It worked
Tags
DropDownList PropertyGrid
Asked by
Guillaume
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or