Completed
Last Updated: 07 Jan 2015 14:31 by ADMIN
ADMIN
Dess | Tech Support Engineer, Sr.
Created on: 18 Dec 2014 14:37
Category: PropertyGrid
Type: Bug Report
0
FIX. RadPropertyGrid - NullReferenceException when using the up/down arrows in the PropertyGridSpinEditor and clicking over the text box
To reproduce:

public Form1()
{
    InitializeComponent();

    this.radPropertyGrid1.SelectedObject = new Item(123, "SampleName");
}

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

    public Item(int id, string name)
    {
        this.Id = id;
        this.Name = name;
    }
}

Activate the editor for the "Id" property and click the up arrow of the PropertyGridSpinEditor. Then click on the text box.

Workaround:

private void radPropertyGrid1_EditorInitialized(object sender, PropertyGridItemEditorInitializedEventArgs e)
{
    PropertyGridSpinEditor spinEditor = e.Editor as PropertyGridSpinEditor ;
    if (spinEditor != null)
    {
        BaseSpinEditorElement spinEditorElement = spinEditor.EditorElement as BaseSpinEditorElement;
        var eventInfo = spinEditorElement.TextBoxItem.HostedControl.GetType().GetEvent("MouseEnter");
        var methodInfo = spinEditorElement.TextBoxItem.GetType().GetMethod("TextBoxControl_MouseEnter",
            System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
        Delegate handler = Delegate.CreateDelegate(typeof(EventHandler), spinEditorElement.TextBoxItem, methodInfo);
        eventInfo.RemoveEventHandler(spinEditorElement.TextBoxItem.HostedControl, handler);

        var eventInfo2 = spinEditorElement.TextBoxItem.HostedControl.GetType().GetEvent("MouseLeave");
        var methodInfo2 = spinEditorElement.TextBoxItem.GetType().GetMethod("textBoxItem_MouseLeave",
            System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
        Delegate handler2 = Delegate.CreateDelegate(typeof(EventHandler), spinEditorElement.TextBoxItem, methodInfo2);
        eventInfo2.RemoveEventHandler(spinEditorElement.TextBoxItem.HostedControl, handler2);
    }
}
Attached Files:
0 comments