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

Disable Parent Node Clicks

5 Answers 430 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Tanya
Top achievements
Rank 1
Tanya asked on 16 Apr 2013, 02:42 PM
hi!

i currently have checkboxes only allowed on child nodes, but when the user clicks on the parent name it automatically checks all child nodes. how can i set the tree, so that the user cannot click on the parent node names, or is able to click, but i don't want the child node checkboxes to all get checked automatically.

the user needs to check the boxes manually one by one.

hope i explained it right.


<telerik:RadTreeView ID="rtvLabs" runat="server" CheckBoxes="true" Skin="Outlook"
                      TriStateCheckBoxes="true" CheckChildNodes="false" SingleExpandPath="true"
                      OnClientNodeChecked="ClientNodeChecked" OnClientNodeClicked="ClientNodeClicked">
                  </telerik:RadTreeView>

in the back end i am setting the nodes as checkable=false; if they are a parent  which gets rid of the checkbox itself, 
, but i guess that isn't enough? how do i prevent the user from selecting ALL child nodes by simply clicking on the parent name?

5 Answers, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 19 Apr 2013, 12:51 PM
Hello Tanya,

You could prevent checking for all child nodes by handling OnClientNodeClicking event and canceling the click for the root nodes:
function OnClientNodeClicking(sender, args) {
    //Chech if clicked node does not have child items
    if (args.get_node().get_level() == 0 || args.get_node().get_lastChild() != null) {
        args.set_cancel(true);
    }
}

All the best,
Hristo Valyavicharski
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Amjad
Top achievements
Rank 1
answered on 28 Jan 2014, 08:55 AM
Hi,
what about if I want to remove the checkbox itself from the parent nodes?
0
Shinu
Top achievements
Rank 2
answered on 28 Jan 2014, 09:48 AM
Hi Amjad,

Please try to set the Checkable property to false to remove the checkbox from the parent node.

JavaScript:
<script type="text/javascript">
    function pageLoad() {
        var tree = $find("<%=RadTreeView1.ClientID %>");
        for (var i = 0; i < tree.get_allNodes().length; i++) {
            if (tree.get_allNodes()[i]._hasChildren() == true)
                tree.get_allNodes()[i].set_checkable(false);
        }
    }
</script>

Thanks,
Shinu.
0
Amjad
Top achievements
Rank 1
answered on 28 Jan 2014, 09:51 AM
Thanks Shinu,

it worked great, also am looking for how make the parent node unselect able or highlighted.

Any ideas?
0
Shinu
Top achievements
Rank 2
answered on 29 Jan 2014, 02:58 AM
Hi Amjad,

Please try to set the set_selected() property of root node to false on OnClientNodeClicked event as follows.

JavaScript:
<script type="text/javascript">
    function OnClientNodeClicked1(sender, args) {
        if (args.get_node()._hasChildren() == true)
            args.get_node().set_selected(false)
    }
</script>

Thanks,
Shinu.

Tags
TreeView
Asked by
Tanya
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Amjad
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or