Completed
Last Updated: 13 Nov 2014 12:15 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 05 Nov 2014 07:41
Category: PropertyGrid
Type: Bug Report
1
FIX. RadPropertyGrid - Property setters are called in wrong order when the editor is active and you toggle PropertyGridCheckBoxItemElement's state
To reproduce: use the following code:

Items _items = new Items();

public Form1()
{
    InitializeComponent(); 

    radPropertyGrid1.SelectedObject = _items;
}

class Items
{
    [Description("A Bool Property")]
    public bool IsEnabled
    {
        get
        {
            return _isEnabled;
        }
        set
        {
            _isEnabled = value;
            RadMessageBox.Show("IsEnabled");
        }
    }
    private bool _isEnabled;

    [Description("A String Property")]
    public string Name
    {
        get { return _name; }
        set
        {
            _name = value;
            RadMessageBox.Show("Name");
        }
    }
    private string _name ;

}

Steps to perform:
1. Change the "Name" property and leave the editor active.
2. Click on the check box to change the "IsEnabled" property.

As a result you will notice that the "IsEnabled" setter is called before the "Name" setter.

Workaround:

Items _items = new Items();

public Form1()
{
    InitializeComponent(); 

    this.radPropertyGrid1.CreateItemElement += radPropertyGrid1_CreateItemElement;        
    radPropertyGrid1.SelectedObject = _items;
}

private void radPropertyGrid1_CreateItemElement(object sender, CreatePropertyGridItemElementEventArgs e)
{
    if (e.ItemElementType == typeof(PropertyGridCheckBoxItemElement))
    {
        e.ItemElementType = typeof(CustomPropertyGridCheckBoxItemElement);
    }
}

public class CustomPropertyGridCheckBoxItemElement : PropertyGridCheckBoxItemElement
{
    public CustomPropertyGridCheckBoxItemElement()
    {
        this.CheckBoxElement.ToggleStateChanging += CheckBoxElement_ToggleStateChanging;
    }

    private void CheckBoxElement_ToggleStateChanging(object sender, StateChangingEventArgs args)
    {
        if (this.PropertyTableElement.ActiveEditor != null && this.PropertyTableElement.SelectedGridItem != this.Data)
        {
            this.PropertyTableElement.EndEdit();
        }
    }

    protected override void DisposeManagedResources()
    {
        this.CheckBoxElement.ToggleStateChanging -= CheckBoxElement_ToggleStateChanging;

        base.DisposeManagedResources();
    }
}
0 comments