Last Updated: 11 Aug 2016 14:04 by ADMIN
Telerik Admin
Created on: 09 Mar 2011 11:13
Category: TreeView
Type: Bug Report
TreeView: Selection doesn't work correctly when equal objects are used in the source collection
When two equal objects are used in the source collection, the first is always selected when you try to select the others.

Workaround when TreeView is not databound.

Instead of adding objects directly in the TreeView's Items Collection, add RadTreeViewItems.
For Example, instead of


 treeView.Items.Add(new RadTreeViewItem(){Header = 1}, 
 treeView.Items.Add(new RadTreeViewItem(){Header = 2}

Workaround when TreeView is databound.

For example , if we databind the treeview to collection of DataItems and some dataitem is located in multiple places in the source collection.
Solution => Wrap the DataItem class in new class - DataItemWrapper. It can hold the underlying DataItem, add additional property  (for exampel ID) and override the Equals and GetHashCode methods.
This way different DataItemWrapper objects can hold equal DataItem objects. In such way if you bind the treeview to collection of DataItemWrappers the selection will be successful.

The XAML team recently reviewed this bug  and won't be adressing it in future. It can be actually considered as feature request because selection should have notion for selected containers.
Unfortunately, the initial code design of the RadTreeView does not have such notion and the complexity of adding such feature now is very big.