Completed
Last Updated: 08 Apr 2016 10:26 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 29 May 2015 10:51
Category: TreeView
Type: Bug Report
1
FIX. RadTreeView - SelectedNodeChanged event is not fired in multiple selection when unselecting the current node
To reproduce: use the following code:

public Form1()
{
    InitializeComponent();

    this.radTreeView1.MultiSelect = true;
    for (int i = 0; i < 3; i++)
    {
        RadTreeNode node = new RadTreeNode();
        node.Text = "Node." + i;
        for (int j = 0; j < 3; j++)
        {
            node.Nodes.Add(new RadTreeNode("Node." + i + "." + j));
        }
        this.radTreeView1.Nodes.Add(node);
    }
    this.radTreeView1.SelectedNodeChanged += radTreeView1_SelectedNodeChanged;
}

private void radTreeView1_SelectedNodeChanged(object sender, Telerik.WinControls.UI.RadTreeViewEventArgs e)
{
    Console.WriteLine(e.Node.Text + ">> Selected: " + e.Node.Selected);
}

1.Select a node
2.Press Ctrl and click over the selected node again in order to unselect it. The SelectedNodeChanged event will not fire.

Workaround:

public class MyRadTreeNode : RadTreeNode
{
    public MyRadTreeNode(string text) : base(text)
    {
    }
    
    private static readonly MethodInfo OnSelectedNodeChangedMethodInfo =
        typeof(RadTreeViewElement).GetMethod("OnSelectedNodeChanged",
            BindingFlags.NonPublic | BindingFlags.Instance, null,
            new Type[] { typeof(RadTreeNode), typeof(RadTreeViewAction) }, null);

    protected override void OnNotifyPropertyChanged(PropertyChangedEventArgs args)
    {
        base.OnNotifyPropertyChanged(args);

        if (args.PropertyName == "Selected" && TreeViewElement != null)
        {
            OnSelectedNodeChangedMethodInfo.Invoke(TreeViewElement, new object[] { this, RadTreeViewAction.ByMouse });
        }
    }
}

0 comments