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

Multiselect and Selecting Parent Items

1 Answer 306 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Valeriu
Top achievements
Rank 1
Valeriu asked on 26 Feb 2013, 04:26 PM
Hello,

The setup:
 - RadTreeView bound to an hierarchy.
 - SelectMode is Multiselect
 - Each node has an IsSelected property, RadTreeViewItem is bound to it using a style.

And one of requirements is that when a child is selected then all his parents should be selected too. And we've run into a problem implementing it.

Reproducing the problem:
 - Expand parent node without selecting
 - Click on a child
 - The Child is selected and his parent too
 - Click again on child
 At this moment parent is unselected by the TreeView, while child is still selected.

Definition of IsSelected property:
public bool IsSelected
{
    get { return isSelected; }
    set
    {
        if (value == isSelected)
            return;
 
        isSelected = value;
        NotifyOfPropertyChange(() => IsSelected);
 
        if (Parent != null)
            Parent.IsSelected = isSelected;
    }
}

When clicking second time on a child, the IsSelected setter isn't called on a child, but sets to false for parent.

Basically I'd like to keep a visual "selection chain" from children to parent nodes. Anything special should be done in order to keep parent nodes selected? 

Thanks

1 Answer, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 01 Mar 2013, 09:41 AM
Hi Valeriu,

In your scenario you mix together the selection logic of the RadTreeView control with your custom logic and this is not working as expected. The multiple selection logic of the control is triggered when the Ctrl key is pressed. Hence when you click on an item for the second time, that logic is not triggered. However, I suggest you to use a CheckBox control to keep the selection of all RadTreeViewItems (parents and children). By doing so you will separate your custom selection logic and the selection logic of the RadTreeView control. Also you will be able to fully customize the selection logic.

In order to implement this approach, each of your items should keep a reference to its parent item (as you already implemented). Also, you can implement methods which will handle the selection of the check boxes (the RadTreeView items respectively). Here you can find detailed information about the implementation of this approach and at the end of the article you can find a link to our CodeLibray section where a ready to use project can be downloaded.

Please try it out and let me know if it works for you.

Kind regards,
Pavel R. Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
TreeView
Asked by
Valeriu
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Share this question
or