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

Select child nodes of parent on click without selecting the parent node

1 Answer 630 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 11 Jul 2013, 09:46 PM
Hi,
Because the dropdowntree API is so sparse (I do not really understand why it does not have the same API as the treeview for that part of the control), I am looking at using the treeview in a combobox.  Assuming the following tree structure:

Two levels only

Level 0a
Level 1a
Level 1b
Level 0b
Level 1c
Level1d

I need to be able to click on a Level 0 item and select its child noes, but not the Level 0 node itself.  In other words, after clicking on Level 0a in the above structure, I need to to look like this:

Level 0a - unchecked
Level 1a - checked
Level 1b - checked
Level 0b -unchecked
Level 1c -unchecked 
Level1d - unchecked 

Is there an easy way to do this?  Also, it would be great if I could uncheck the nodes in the other branches as well.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 14 Jul 2013, 06:53 AM
Hi Brian,

Please have a look at the following code I tried which works fine at my end. When the user select a node by clicking it, that particular RadTreeNode gets expanded with all its child nodes checked.

ASPX:
<telerik:RadTreeView ID="RadTreeView1" runat="server" CheckBoxes="true" OnClientNodeClicked="OnClientNodeClicked">
    <Nodes>
        <telerik:RadTreeNode Value="PersonalFolders" Checkable="false" ImageUrl="../Images/Fol1.JPG"
            AllowEdit="false" Text="Personal Folders">
            <Nodes>
                <telerik:RadTreeNode Value="PublicFolders1" ImageUrl="../Images/SD.png" AllowEdit="false"
                    Text="Public folders1" Font-Bold="true">
                </telerik:RadTreeNode>
                <telerik:RadTreeNode Value="PublicFolders2" ImageUrl="../Images/SD.png" AllowEdit="false"
                    Text="Public folders2" Font-Bold="true">
                </telerik:RadTreeNode>
            </Nodes>
        </telerik:RadTreeNode>
        <telerik:RadTreeNode Value="PrivateFolders" Checkable="false" ImageUrl="../Images/Lock2.JPG"
            AllowEdit="false" Text="Private Folders">
            <Nodes>
                <telerik:RadTreeNode Value="PrivateFolders1" ImageUrl="../Images/SD.png" AllowEdit="false"
                    Text="Private Folders1" Font-Bold="true">
                </telerik:RadTreeNode>
                <telerik:RadTreeNode Value="PrivateFolders2" ImageUrl="../Images/SD.png" AllowEdit="false"
                    Text="Private Folders2" Font-Bold="true">
                </telerik:RadTreeNode>
            </Nodes>
        </telerik:RadTreeNode>
    </Nodes>
</telerik:RadTreeView>

JavaScript:
<script type="text/javascript">
    function OnClientNodeClicked(sender, args) {
        args.get_node().expand();
        var childelements = args.get_node().get_allNodes();
        for (var counter = 0; counter < childelements.length; counter++) {
            childelements[counter].set_checked(true);
        }
    }
</script>

If you don't want the parent node to remain as selected, you can try the this code. args.get_node().set_selected(false);

Thanks,
Shinu.
Tags
TreeView
Asked by
Brian
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or