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

multi selection on parent nodes

1 Answer 91 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
cp
Top achievements
Rank 1
cp asked on 14 Aug 2012, 01:25 PM
Hi,
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:
Parent1
  - Child1
  - Child2
Parent2
  - Child1
  - Child2
  - Child3
Parent3
  - 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?

Thanks,

1 Answer, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 17 Aug 2012, 09:59 AM
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,
Jack
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
Treeview
Asked by
cp
Top achievements
Rank 1
Answers by
Jack
Telerik team
Share this question
or