Event Fired for Unselecting Node

4 posts, 0 answers
  1. Richard
    Richard avatar
    10 posts
    Member since:
    Dec 2007

    Posted 18 Apr 2008 Link to this post

    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.
  2. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 21 Apr 2008 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Richard
    Richard avatar
    10 posts
    Member since:
    Dec 2007

    Posted 21 Apr 2008 Link to this post

    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
  5. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 22 Apr 2008 Link to this post

    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
Back to Top