Same Child Object, Multiple Roots

3 posts, 1 answers
  1. Bobby
    Bobby avatar
    6 posts
    Member since:
    Jun 2014

    Posted 02 Jun 2014 Link to this post

    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. Bobby
    Bobby avatar
    6 posts
    Member since:
    Jun 2014

    Posted 02 Jun 2014 in reply to Bobby Link to this post

    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>();
            }
        }
  3. UI for WPF is Visual Studio 2017 Ready
  4. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 05 Jun 2014 Link to this post

    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.
     
Back to Top