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

Troube With Tri State Checkboxes

4 Answers 89 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Al
Top achievements
Rank 1
Al asked on 12 Jan 2012, 05:20 PM
Hi there, I'm having trouble getting Tri-State checkboxes to work as I assume they should. My TreeView is data bound on the server side to a collection of objects with the following code:
tree.DataTextField = "Name"
tree.DataValueField = "NodeID"
tree.DataFieldID = "NodeID"
tree.DataFieldParentID = "ParentNodeID"
tree.DataSource = nodes
tree.DataBind()

The TreeView itself is declared thusly:
<tel:RadTreeView runat="server" ID="trvHierarchy"  CheckBoxes="true" CheckChildNodes="false" OnNodeDataBound="TreeNodeDataBound" OnNodeCheck="HierarchyTreeNodeCheck"></tel:RadTreeView>
You'll notice that Tri-State Checkboxes is absent from that declaration, I'll get to that shortly...
The NodeDataBound event is where I am setting the checked property of various nodes, the decision of wheather to check a node or not is based on other data that  is contained in a member variable of the UserControl that this Tree lives in.
Protected Sub TreeNodeDataBound(ByVal sender As Object, ByVal args As RadTreeNodeEventArgs)
       If Not args.Node Is Nothing Then
           Dim check As Boolean = False
           For Each assignedNode As KeyValuePair(Of Integer, String) In _assignments
               If assignedNode.Key = CType(args.Node.Value, Integer) Then
                   check = True               
               End If
           Next
           If check Then
               args.Node.Checked = True
           Else
               args.Node.Checked = False
           End If
 
 
       End If
   End Sub
Now, when I leave out the Tri-State Checkboxes from the declaration, the code behaves exactly as I would expect, the nodes that are supposed to be checked are and the ones that are not aren't. What I would prefer however,  is to enable the tri-state behavior with the desired result being that the parent nodes of any checked noes will show as "indeterminate" if not all the children are checked and checked if they are so my users will have a cue to where the checked noes are without expanding the entire tree, My problem is that when I set Tri-state checkboes to true, the code executes correctly and sets the checked property of the desired nodes, but in the browser absolutely no nodes are checked or indeterminate. 

I'm using version 2010.1.309.20 of the Telerik.Web.UI.dll

Thank You,

Al Irvine

4 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 17 Jan 2012, 04:01 PM
Hi Al,

 
You can try to use the RadTreeView DataBound server event and prevent changing the check state of the nodes that have child nodes as in the code:

protected void RadTreeView1_DataBound(object sender, EventArgs e)
   {
       foreach (RadTreeNode node in RadTreeView1.GetAllNodes())
       {
           if (node.Nodes.Count>0)
           {
               continue;
           }
 
          //your logic....
       }
 
   }

Hope this helps.

Regards,
Plamen Zdravkov
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
Chris Salas
Top achievements
Rank 1
answered on 17 Jan 2012, 07:23 PM
Did anyone figure this out?  The issue i am having right now is that with the Tri-State check boxes a minimum of one of the final branch nodes has to be selected.  If this is not the case then none of the other check boxes will show as checked even if you set them to checked.  I have been trying to find a way around this with no avail.  Al i think this could be your issue.
0
Al
Top achievements
Rank 1
answered on 18 Jan 2012, 09:17 PM
Hi Chris,

So far I've had no luck, but your suggestion is intriguing...
My situation definitely falls into what you are describing, as all of the nodes I have tested have further children that are not checked. I'll do some testing and see if that gets the tri-states working, but if it does I'm back to square one as I don't actually want those nodes to be checked.

Plamen, I'm not sure I follow you. It seems you are suggesting that if a node has any children I shouldn't bother setting it to checked and if it doesn't I can go ahead and apply my logic. This would seem to be a solution to the problem Chris described, but it doesn't help solve our problems.

Given a node structure like so:

  - B
     -C
     -D
E

I expect that if I set B to "checked" in NodeDataBound that A and B will show the indeterminate state and C will show as checked. What I'm starting to suspect is that until one of C or D (children of B) is checked I won't see any nodes as checked at all. If that is correct and by design, then I'm content to give up on tri-states, but I'd really like to use it so I don't have to expand my tree to all the checked nodes as it's a rather large tree.

Thanks for the help,

Al Irvine
0
Plamen
Telerik team
answered on 20 Jan 2012, 04:21 PM
Hi,

 
You can try to set the desired check state from the client-side as shown in the code:

function OnClientLoad(sender, args) {
 
           var tree = $find("<%= RadTreeView1.ClientID %>");
           tree.trackChanges();
           tree.findNodeByText("King").set_checked(true);
           tree.commitChanges();
       }

Hope this will help.

Regards,
Plamen Zdravkov
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
Tags
TreeView
Asked by
Al
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Chris Salas
Top achievements
Rank 1
Al
Top achievements
Rank 1
Share this question
or