Question

I try to select all child nodes if the parent node is selected. I'm using a radTreeView from Telerik WinControls. I tried to use the radTreeView_SelectedNodeChanged() and got this code:

private void machinesTreeView_SelectedNodeChanged(object sender, RadTreeViewEventArgs e)
{
    for (int w = 0; w < machinesTreeView.SelectedNode.Nodes.Count; w++)
    {
        machinesTreeView.SelectedNode = machinesTreeView.SelectedNode.Nodes[w];
    }
}

I debugged it because its just selecting the first one. And then I'd seen that it's logical that it just selects the first one. Because if the code executes

machinesTreeView.SelectedNode = machinesTreeView.SelectedNode.Nodes[w];

it selects a new one so the SelectedNodeChanged event is fired again and then the for loop is unnecessary because there aren't any child nodes on a child node.

So my question is if there is another (maybe better) way to do that?

Suggestions appreciated :)

Was it helpful?

Solution

Seems that you have a bug in your handler. If you want to select all subnodes try this:

    private void machinesTreeView_SelectedNodeChanged(object sender, RadTreeViewEventArgs e)
    {
        for (int w = 0; w < machinesTreeView.SelectedNode.Nodes.Count; w++)
        {
            machinesTreeView.SelectedNode.Nodes[w].Selected = true;
        }
    }

Do not forget to enable multiselect feature:

machinesTreeView.MultiSelect = true;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top