multi selection on parent nodes

2 posts, 0 answers
  1. cp
    cp avatar
    44 posts
    Member since:
    Oct 2012

    Posted 14 Aug 2012 Link to this post

    I have several parent nodes, and what I would like to do is be able to multi select the parent nodes and the child nodes in such a way that only one node under a parent or the parent can be selected.

    For instance, suppose I have this example:
      - Child1
      - Child2
      - Child1
      - Child2
      - Child3
      - Child1

    I would like to be able to start off with all the Parent nodes selected, and then be able to do any combination thereafter by only having one node from each parent selected at any time.

    I have tried Canceling the selection event in the SelectedNodeChanging handler (by removing the event handler, then programatically setting the selected nodes, and finally adding the handler back) however the tree view does not refresh.

    Is there perhaps a built in way of achieving this or am I going about it all wrong?

  2. Jack
    Jack avatar
    2335 posts

    Posted 17 Aug 2012 Link to this post

    Hello cp,

    If I understand correctly, only one child node can be selected in your scenario. When selecting another node, the previous selected child node will be deselected. If this is the case, you can customize RadTreeView selection behavior by handling the SelectedNodeChanging method. Consider the sample below:
    void TreeViewElement_SelectedNodeChanging(object sender, RadTreeViewCancelEventArgs e)
        RadTreeNode oldNode = this.tree.SelectedNode;
        RadTreeNode newNode = e.Node;
        if (newNode.Parent != null)
            foreach (RadTreeNode node in newNode.Parent.Nodes)
                if (node.Selected && node != newNode)
                    node.Selected = false;

    I hope this helps. If you have further questions, do not hesitate to ask.
    All the best,
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  3. DevCraft banner
Back to Top