This is a migrated thread and some comments may be shown as answers.

Event Fired for Unselecting Node

3 Answers 70 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 18 Apr 2008, 04:24 PM
I'm looking for a way to determine when the SelectedNodes property changes.

When an item is added to SelectedNodes, this is easy because the Selected and Selecting events are fired.  I know there's no corresponding event for unselecting a node.  However, is there any other event that is fired when the selection status of a node changes?

Thanks for your help.

3 Answers, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 21 Apr 2008, 01:26 PM
Hello License Developer,

Thank you for writing.

RadTreeView currently supports notifications only when a node is being selected. We are planning to provide a way to tell when a node is being unselected. 

At the moment, I cannot give you a specific timeframe. For now, you could try keeping track of selected nodes and determine when a node gets unselected.

Please let us know whether this functionality is critical to your project at this point. If this is the case, we will increase the priority of this feature.

If you have any additional questions, please contact me.

Regards,
Jordan
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Richard
Top achievements
Rank 1
answered on 21 Apr 2008, 05:29 PM
Thanks for getting back with me.

I'm new to using Telerik controls and posting to your site (I'll try to change my posting ID so that it shows my name instead of "Licensed Developer).

Having an event that lets a user explicitly know when an item is unselected would be perfect and I look forward to that in the future.  In the meantime, I'd like to use the approach that I think you were suggesting, which would be to make a copy of the SelectedNodes property and then compare the copy periodically with the SelectedNodes property to see if it changed.

The problem I have with implementing this approach is knowing when the selection status of a node changes or might have changed.  The only event that I know of that fires when the selection is changed (either by a mouse click or using the keyboard) is the PropertyChanged event.  Unfortunately, it fires for every displayed node, even when the selection status of a single node is all that changes.

Is there any event of either a tree or node that I can count on to fire (besides the PropertyChangedevent) when an item might have been unselected so that I can check if the selection status of nodes actually changed?

Thanks,
Richard F. Kutz
0
Jordan
Telerik team
answered on 22 Apr 2008, 11:21 AM
Hello Richard,

A node usually becomes unselected due to another node becoming selected. I would "keep track" of the selected nodes this way:

List<RadTreeNode> oldSelectedNodes = new List<RadTreeNode>(); 
 
public Form1() 
    InitializeComponent(); 
    this.radTreeView1.AllowMultiselect = true
 
    this.radTreeView1.Selected += new EventHandler(radTreeView1_Selected); 
    this.oldSelectedNodes.AddRange(this.radTreeView1.SelectedNodes); 
 
void radTreeView1_Selected(object sender, EventArgs e) 
    bool multiSelect = (Control.ModifierKeys == Keys.Control || Control.ModifierKeys == Keys.Shift); 
    int selectedNodeCount = (multiSelect) ? this.radTreeView1.SelectedNodes.Count : 1; 
 
    Console.WriteLine("Selected nodes: {0}", selectedNodeCount); 
 
    int i; 
    List<RadTreeNode> selectedNodes = new List<RadTreeNode>(selectedNodeCount); 
    for (i = 0; i < selectedNodeCount; i++) 
    { 
        selectedNodes.Add(this.radTreeView1.SelectedNodes[i]); 
    } 
 
    i = 0; 
    while (i < this.oldSelectedNodes.Count) 
    { 
        RadTreeNode node = this.oldSelectedNodes[i]; 
        if (!selectedNodes.Contains(node)) 
        { 
            Console.WriteLine("Node {0} got unselected.", node.Text); 
            this.oldSelectedNodes.RemoveAt(i); 
        } 
        else 
        { 
            i++; 
        } 
    } 
 
    foreach(RadTreeNode node in selectedNodes) 
    { 
        if(!this.oldSelectedNodes.Contains(node)) 
        { 
            this.oldSelectedNodes.Add(node); 
        } 
    } 


Hope this helps.

Kind regards,
Jordan
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Treeview
Asked by
Richard
Top achievements
Rank 1
Answers by
Jordan
Telerik team
Richard
Top achievements
Rank 1
Share this question
or