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

RadTreeView Bind One Tree To Another

1 Answer 70 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Marin
Top achievements
Rank 1
Marin asked on 28 Mar 2016, 01:30 PM

Hello,I'm new in WPF. Let me explain you what is my case. So i have three RadTreeView, my point is, is it possible when I expand one of the the item in the first tree automatically to expand the same element in the others trees? And I have another question how to make every line in the RadTreeView to be different color?

For example 1, 3, 5, 7 line to be gray, and 2,4,6,8 to be white.

 

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 30 Mar 2016, 07:44 AM
Hello Marin,

Expanding / Selecting a particular item a RadTreeView in code can be achieved with GetItemByPath() / BringPathIntoView() / SelectitemByPath() / ExpandItemByPath() methods which are very similar.  Generally, if you organize your ViewModels to provide a Path property (or method) you can access (or select/expand) a particular RadTreeViewItem (the container for the viewmodel) with these functions.

In your scenario, it is important whether the same (or some of the) viewmodels (objects) reside in multiple RadTreeView instances. If an object is both in trees A B and C, you need the paths for this object for every tree. You can store such paths, for example in dictionary per tree or in dictionary per object. Once such object is selected/expanded via its container (RadTreeViewItem) in tree A, you can use the Expanded / SelectionChanged event,  get this object , and expand/select/bring this object in the other trees, having its path available. Also, if you two-way bind the IsSelected property of the RadTreeViewItem to some boolean property of the object (viewModel), the object will be selected in all trees. 

If your trees use entirely different sets of objects , you need to have matching dictionary - or way to say that object x in tree A matches the object y in tree B. Then use the same approach - when expand / select the first, get the matching second object and use its path in combination with the get-item-by-path functions.

Regarding the alternation colors, this can be achieved with ItemContainerStyleSelector or ItemTemplateSelector - just select different template / style based on the index of the given object.

Regards,
Petar Mladenov
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
TreeView
Asked by
Marin
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or