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

Selecting only parent node?

1 Answer 31 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
V
Top achievements
Rank 1
V asked on 28 Jun 2010, 07:56 PM
After trying for hours to accomplish something that in theory should be a simple task, i've decided to turn to the forums for help!

I have a tree view (with checkboxes) with ONE parent node, and multiple child nodes.

I also have an asp:OptionButtonList, with three options: Full, Partial, and None.

If a user clicks "Full", the Parent node and child nodes should be checked.

If a user clicks "Partial", only the Parent node should be checked...no child nodes.

And, obviously, if a user clicks "None", no nodes should be checked.

I can get the Full and None options to work...but not the partial.

Can anyone help?

So far i'm doing this:

switch (rbl.SelectedValue)  
            {  
                case "Full":  
                    radTreeView.CheckAllNodes();  
                    return;  
                case "None":  
                    isChecked = false;  
                    break;  
                case "Partial":  
                    isChecked = false;  
                    break;  
                default:  
                    break;  
            }  
 
            foreach (RadTreeNode node in radTreeView.Nodes)  
            {           
                node.Checked = isChecked;                  
            } 

obviously this isn't going to accomplish what I want for the "Partial" option, but i've tried what seems like a billion different things, and I can't seem to just check the Parent Node...

Thanks in advance!
V

1 Answer, 1 is accepted

Sort by
0
Nikolay Tsenkov
Telerik team
answered on 30 Jun 2010, 11:08 AM
Hi V,

Well you can check if a node has children => it's parent node (non-terminal/not a leaf node):
bool isPartial = false;
switch (rbl.SelectedValue) 
    case "Full"
        radTreeView.CheckAllNodes(); 
        return
    case "Partial":
        isPartial = true
        break
    default
        break
var allNodes = radTreeView.GetAllNodes();
foreach (RadTreeNode node in allNodes) 
{
    bool isChecked = false;
    if (isPartial)
    {
        if (node.Nodes.Count > 0)
            isChecked = true;
    }
    node.Checked = isChecked;                 
}

This should work for you!


Regards,
Nikolay Tsenkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
V
Top achievements
Rank 1
Answers by
Nikolay Tsenkov
Telerik team
Share this question
or