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

Tree View List Show Intermediate State

1 Answer 59 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 04 Sep 2019, 10:30 AM

Hi

I have a tree view list which connects to a datasource and saves which nodes have been checked into a grid. When I load the page again I want to be able to take what is in the grid and check the corresponding nodes again. This is the code I have wrote so far, when the page loads it reads the datatable and checks the parent and child nodes which match the data. However it is checking all of the child nodes even though not all of the nodes appear in the datatable, how can I check the parent node in an intermediate state?

                DataTable Branches = new DataTable();
                DataSourceSelectArguments args = new DataSourceSelectArguments();
                DataView view = (DataView)sdsCampaignBranch.Select(args);
                if (view != null)
                    Branches = view.ToTable();

                tvBranches.DataBind();

                foreach (RadTreeNode parent in tvBranches.Nodes)
                {
                    foreach (RadTreeNode child in parent.Nodes)
                    {
                        for (int j = 0; j < Branches.Rows.Count; j++)
                        {
                            if (parent.Attributes["ItemValue"].ToString() == Branches.Rows[j][0].ToString().Trim())
                            {
                                parent.Checked = true;
                            }

                            if (child.Attributes["ItemValue"].ToString() == Branches.Rows[j][1].ToString().Trim())
                            {
                                child.Checked = true;   
                            }          
                        }
                    }
                }

1 Answer, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 09 Sep 2019, 10:02 AM

Hello Alex,

When the TriStateCheckBoxes="true" property is present in the TreeView configuration, then checking the child node would automatically set the parent node's state to Indeterminate. This state is then available through the CheckState read-only property of the Node.

With that said, if you need to set Indeterminate state of a node, you just need to have at least one of its child nodes to be checked and the TreeView will mark it Indeterminate itself.

Regards,
Peter Milchev
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
TreeView
Asked by
Alex
Top achievements
Rank 1
Answers by
Peter Milchev
Telerik team
Share this question
or