Populating a TreeListView With a Generic List

3 posts, 0 answers
  1. Rob
    Rob avatar
    12 posts
    Member since:
    Apr 2012

    Posted 01 Oct 2012 Link to this post

    I have an MVVM WPF app with a RadTreeListView that is populated via a Generic List<T> using nested sets from a database. Only the first column of the TreeListView gets populated. What class would be appropriate to replace the generic List so that I can pass multiple columns of data to the TreeListView?

    I posted this same question, with code, on the WPF Forum of MSDN and was told that my existing approach with List<T> should work with the TreeListView.  I was also told that since the question involves a third party control, i.e., Telerik, I should move the question to the Telerik forum.

    My xaml showing the data binding:
    <telerik:RadTreeListView.Columns>
      <telerik:GridViewDataColumn DataMemberBinding="{Binding Tag}"
                                  Header="Tag"
                                  Width="Auto"/>
      <telerik:GridViewDataColumn DataMemberBinding="{Binding Description}"
                                  Header="Description"
                                  Width="Auto" />
      <telerik:GridViewDataColumn DataMemberBinding="{Binding ImportedEquipmentType}"
                                  Header="Imported Equipment Type"
                                  Width="Auto"/>       
    </telerik:RadTreeListView.Columns>
    The "Description" and "Imported Equipment Type" columns do not get populated.

    My code for my data class is as follows. My xaml ItemSource is bound to Children:

    public class TagItem
    {
        public List<TagItem> _children = new List<TagItem>();
        public List<TagItem> Children
        {
            get { return _children; }
        }
        public string EquipmentID { get; set; }
        public string SystemID { get; set; }
        public string Tag { get; set; }
        public string TagNodeText { get; set; }
        public string Tag2 { get; set; }
        public string Description { get; set; }
        public string Description2 { get; set; }
        public string ImportedEquipmentType { get; set; }
        public string ManuallyAdded { get; set; }
        public string ParentID { get; set; }
        public string NodeLeft { get; set; }
        public string NodeRight { get; set; }
        public string Depth { get; set; }
        public string Mpath { get; set; }
    }

    The constructor for my navigator ViewModel is:
    readonly EquipmentListTreeViewModel _equipmentTree;
     
    public EquipmentListNavigator()
    {
        InitializeComponent();
     
        // Get raw family tree data from a database.
        TagItem rootTagItem = Database.GetEquipmentTree();
     
        // Create UI-friendly wrappers around the
        // raw data objects (i.e. the view-model).
        _equipmentTree = new EquipmentListTreeViewModel(rootTagItem);
     
        // Let the UI bind to the view-model.
        base.DataContext = _equipmentTree;
    }

    And the service that fills the list:
    public static TagItem GetEquipmentTree()
    {
        nTI.Tag = "ASSET REGISTER";
        FillTreeView("", nTI);        
        return nTI;
    }
     
    private static void FillTreeView(string currKeyRoot, TagItem nTI = null)
    {
        DataRows.MyRow row = drows.GetNextRow();
        while (row != null)
        {
            if (NodeStartsWith(row.MPath, currKeyRoot))
            {
                TagItem tnChild = new TagItem();
                tnChild.SystemID = row.SystemID;
                tnChild.EquipmentID = row.EquipmentID;
                tnChild.Description = row.Description;
                tnChild.ParentID = row.ParentID;
                tnChild.Mpath = row.MPath;
                tnChild.Depth = row.Depth;
                tnChild.Tag = row.Tag;
                tnChild.Tag2 = row.Tag2;
                tnChild.Description2 = row.Description2;
                tnChild.ImportedEquipmentType = row.ImportedEquipmentType;
                tnChild.ManuallyAdded = row.ManuallyAdded;
                tnChild.NodeLeft = row.NodeLeft;
                tnChild.NodeRight = row.NodeRight;
     
                nTI.Children.Add(tnChild);                   
                FillTreeView(row.MPath, tnChild);
            }
            else
            {
                drows.MovePrev();
                return;
            }
            row = drows.GetNextRow();
        }


    All of this works except that the tree is populated only in the "Tag" column. "Description" and "Imported Equipment Type" are blank.
  2. Rob
    Rob avatar
    12 posts
    Member since:
    Apr 2012

    Posted 05 Oct 2012 Link to this post

    It has been a while since I posted this question.  Has anybody looked at it?
  3. UI for WPF is Visual Studio 2017 Ready
  4. Rob
    Rob avatar
    12 posts
    Member since:
    Apr 2012

    Posted 09 Oct 2012 Link to this post

    Never mind.  I finally figured it out on my own.
Back to Top