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

treeview checkstate always Unchecked

1 Answer 113 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mohan
Top achievements
Rank 1
Mohan asked on 23 Sep 2009, 01:04 AM
I have  following radtreeview  defined

 <telerik:RadTreeView ID="tvGroups"  runat="server" TriStateCheckBoxes="true" CheckBoxes="true" OnClientNodeChecked="nodeChecked" >
        </telerik:RadTreeView>


On the server I have the following code.
 foreach (RadTreeNode node in tvGroups.CheckedNodes)
            {
                Trace.Warn("Value: " + node.Value + ":: Text: " + node.Text +" :: Checked: " + node.Checked.ToString() + ":: CheckedState: " + node.CheckState.ToString());
                if (node.CheckState == TreeNodeCheckState.Checked)
                {
                      //Do something only if the Checkbox is checked.
                      //Ignore if its indeteminate.
                }
            }

The problem is that the CheckState is always Unchecked. I am not sure what I am doing wrong.

THanks



1 Answer, 1 is accepted

Sort by
0
Mohan
Top achievements
Rank 1
answered on 23 Sep 2009, 03:34 PM
after some more testing, I want to some of my findings,

I have the following data in the treeview
Root
   -     Node1
            - Subnode 11
   -     Node2
   -     Node3
   -     Node4
            -subnode41


All the nodes are Checkable. I have not enabled CheckChildNodes.

I am also setting the parent node value to indeterminant on the client side using the code below.
function nodeChecked(sender, args)  
{  
    var node = args.get_node();  
    var parent = node.get_parent();  
    if(parent != sender)  
    {  
        if(node.get_checked() == true)  
        {  
            //sender._checkChildNodes = false;
            //parent.set_checked(true);
            parent.get_checkBoxElement().className = "rtIndeterminate";
           //sender._checkChildNodes = true;  
        }  
        else
        {  
            var isChildChecked = false;  
            for(var i=0;i<parent.get_nodes().get_count();i++)  
            {  
                if(parent.get_nodes().getNode(i).get_checked())  
                    isChildChecked = true;  
            }  
              
            if(!isChildChecked)  
                parent.set_checked(false);  
        }  
    }
}


The issue I am having is that if I select Node4 and submit then in the CheckedNodes collection, I have Root node and the Node4. The Checked value in both the nodes are true but the CheckState value is Unchecked. The CheckState value should be indeterminate for
the Root node and Checked for Node4

If I select  subnode41 then the CheckedNodes collection has the Root, Node4 and the subnode41 nodes. The Checked value is true for all 3 of the nodes and the CheckState value is Indeterminate for the Root node, Checked for Node4 and subnode41.  The CheckState value should be Indeterminate for the Root and Node4  nodes and Checked for the subnode41.

I am not sure why the CheckState value is not behaving as expected.


Tags
TreeView
Asked by
Mohan
Top achievements
Rank 1
Answers by
Mohan
Top achievements
Rank 1
Share this question
or