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

Checkbox Behavior

1 Answer 71 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Adrian de Freitas
Top achievements
Rank 1
Adrian de Freitas asked on 30 Aug 2010, 07:35 PM
I would like to be able to "couple" and "de-couple" the cascading behavior of a checkbox in the treeview at will.  Specifically, I am looking for the following:

1.  Make it such that the topmost nodes in the tree (i.e. Level 1), when checked/unchecked, check/uncheck all underlying child nodes.
2.  Make it such that all nodes at level 2 or below, when checked/unchecked, does NOT check/uncheck all parent OR child nodes.
3.  Make it such that the topmost nodes in the tree (i.e. Level 1) are either checked, unchecked, or indeterminate, based on the checkstate of the underlying child nodes.

Use Case:  I am using the treeview to describe a military chain of command in which the topmost nodes represent countries and all child nodes represent individual units (some units can have subordinate units under them which appear as children).  I want to bind the checkbox to the Visibility property of a control so that users can easily show/hide units by manipulating the checkboxes.  When they check the country checkbox, they should be able to show/hide all underlying units.  When they check individual units, however, they are only toggling the visibility of that specific unit.

Can the treeview control be configured to do this?

1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 02 Sep 2010, 04:21 PM
Hello Adrian de Freitas,

The RadTreeView doesn't implement this scenario out-of-the-box. You will need to manually change the  CheckState of each item accordingly to your needs.

Also, I am not sure if I understand your scenario completely. It seems to me as though you need to expand and collapse the Items instead of show/hide them? Is that the case or am I missing something? Can you please elaborate a bit more?

Because if you need to check an item and expand all its sub Items thus displaying them, you can handle the Checked() and Unchecked() events:
private void myTreeView_Checked(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
    RadTreeViewItem checkedItem = e.Source as RadTreeViewItem;
    if (checkedItem.Level == 0)
        checkedItem.ExpandAll();
}
 
private void myTreeView_Unchecked(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
    RadTreeViewItem checkedItem = e.Source as RadTreeViewItem;
    if (checkedItem.Level == 0)
    {
        checkedItem.IsExpanded = false;
    }
}

Sincerely yours,
Tina Stancheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
Adrian de Freitas
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or