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

Update checked state

5 Answers 147 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 1
Erik asked on 19 Dec 2008, 03:24 PM
Hello,

I have a treeview with some rootitems and each rootitem has some children. The children have two states (checked - unchecked) and the rootitems have three states (checked - unchecked - undefined). This works great when I click the items with my mouse.

I added every item in code. I also set the CheckState property of the children to On or Off. Is there an easy way to update the CheckState of the rootitems? Changing the CheckState of the children does not trigger for and update of the parent.

Thanks in advance,

Erik

5 Answers, 1 is accepted

Sort by
0
Konstantin Petkov
Telerik team
answered on 22 Dec 2008, 02:39 PM
Hi Erik,

I just tried your scenario initializing the treeview dynamically. I set a child node's CheckedState to ToggleState.On and another one -- ToggleState.Off. I get the expected result -- the parent root node has the third state. Please find attached an image showing the result as well as the code I'm using below:

        private void InitializeTreeView2() 
        {  
            RadTreeViewItem rootItem = new RadTreeViewItem(); 
            rootItem.Header = "RootItem1"
             
            RadTreeViewItem item = new RadTreeViewItem(); 
            item.Header = "Item11"
            item.CheckState = System.Windows.Automation.ToggleState.On; 
            rootItem.Items.Add(item); 
 
            item = new RadTreeViewItem(); 
            item.Header = "Item12"
            item.CheckState = System.Windows.Automation.ToggleState.Off; 
            rootItem.Items.Add(item); 
 
            RadTreeView2.Items.Add(rootItem); 
 
            rootItem = new RadTreeViewItem(); 
            rootItem.Header = "RootItem2"
            RadTreeView2.Items.Add(rootItem); 
        } 
 

I'm working with the latest SP2 of RadControls for Silverlight Q3 2008 we released last week.

Is there any difference in the code you use?

Regards,
Konstantin Petkov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Erik
Top achievements
Rank 1
answered on 24 Dec 2008, 12:32 PM
Hi Konstantin,

My code is the same, and I have installed the latest version. In your screenshot you have expanded RootItem1, but what is the state of RootItem1 before you expand it?

Erik
0
Konstantin Petkov
Telerik team
answered on 26 Dec 2008, 07:54 AM
Hi Erik,

I see where your confusion comes from. Indeed, the while collapsed, the root item is unchecked. I'm afraid this is expected though as If you check the child nodes manually, the root item needs to be expanded first. In your case the root item checked state is processed when you expand the root item and get the checked state of the child items -- that's where the root item checked state makes sense.

I hope my explanation helps. Let us know if you have further questions.

Greetings,
Konstantin Petkov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Erik
Top achievements
Rank 1
answered on 05 Jan 2009, 08:50 AM
Hi Konstantin,

I understand your explanation, but in my opinion this is NOT expected behaviour. If you have the possibility to set the checked state of a child, you also have to have a possibility to update the parent.

Imagine I want to save the state of each child to a database and later load the states again. In code I can set the states of the childs, but I can't update the parents to show the right state while they are collapsed. So the first view to the rootitems is wrong.

Erik
0
Valentin.Stoychev
Telerik team
answered on 07 Jan 2009, 01:03 PM
Hi Erik,

For the scenario you describe you will have to manually set the CheckState of the root items after you add their respective children in your code. You can do this as follows:

rootItem.CheckState = System.Windows.Automation.ToggleState.Indeterminate;

We also fixed a minor bug in the CheckState mechanism and that is why I am sending you an updated version of our controls along with a sample project. Let me know if you need further assisstance.

Greetings,
Valentin.Stoychev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
TreeView
Asked by
Erik
Top achievements
Rank 1
Answers by
Konstantin Petkov
Telerik team
Erik
Top achievements
Rank 1
Valentin.Stoychev
Telerik team
Share this question
or