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

Same Child Object, Multiple Roots

2 Answers 29 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Bobby
Top achievements
Rank 1
Bobby asked on 02 Jun 2014, 03:48 PM
I am using a TreeListView and have multiple roots on my tree but they share a common child.
A -> B
D -> B
B -> C

I would expect to see two roots A and D which expand out to
A
  B
    C
D
  B
    C
The TreeListView roughly displays this but expanding and collapsing is behaving strangely.
If I expand B it sometimes expands both Bs and sometimes C becomes its own row that will not collapse into B.
Can someone help explain this behavior to me?






















































2 Answers, 1 is accepted

Sort by
0
Bobby
Top achievements
Rank 1
answered on 02 Jun 2014, 04:02 PM
Here is an example

.xaml
<telerik:RadTreeListView
        CanUserDeleteRows="False"
        CanUserInsertRows="False"
        IsReadOnly="True"
        HorizontalAlignment="Left"
        Height="413"
        EnableRowVirtualization="False"
        VerticalAlignment="Top"
        AutoGenerateColumns="False"
        Width="725"
        ItemsSource="{Binding Roots}">
        <telerik:RadTreeListView.ChildTableDefinitions>
            <telerik:TreeListViewTableDefinition ItemsSource="{Binding Children}" />
        </telerik:RadTreeListView.ChildTableDefinitions>
        <telerik:RadTreeListView.Columns>
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"
                                    Header="Name" />
        </telerik:RadTreeListView.Columns>
    </telerik:RadTreeListView>

bound object

        public ObservableCollection<Node> Roots
        {
            get
            {
                var relationships = new ObservableCollection<Node>();
                var nodeA = new Node("A");
                var nodeB = new Node("B");
                var nodeC = new Node("C");
                var nodeD = new Node("D");
                nodeA.Children.Add(nodeB);
                nodeB.Children.Add(nodeC);
                nodeD.Children.Add(nodeB);
                relationships.Add(nodeA);
                relationships.Add(nodeD);
                return relationships;
            }
        }

    public class Node
    {
        public string Name { get; private set; }
        public DateTime Expiry { get; private set; }
        public ObservableCollection<Node> Children { get; private set; }

        public Node(string name)
        {
            this.Name = name;
            this.Children = new ObservableCollection<Node>();
        }
    }
0
Accepted
Dimitrina
Telerik team
answered on 05 Jun 2014, 07:00 AM
Hi,

It is not recommended displaying the same items under different nodes as it may lead to problems like the ones you have hit. You will have to add separate child instances under the different child nodes.

Regards,
Didie
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
TreeListView
Asked by
Bobby
Top achievements
Rank 1
Answers by
Bobby
Top achievements
Rank 1
Dimitrina
Telerik team
Share this question
or