Search code examples
c#.netlistviewtreeviewobjectlistview

How to populate BrightIdeasSoftware.TreeListView ?


I just downloaded ObjectListView, and have an issue with populating it.

I got list of MyObject:

public class MyObject
{
  public int Id { get; set; }
  public int ParentId { get; set; }
  public string Name { get; set; }

  public int Data { get; set; }

  public MyObject(int id, int parentId, string name, int data)
  {
     Id = id;
     ParentId = parentId;
     Name = name;
     Data = data;
  } 
}

List<MyObject> list = List<MyObject>();

I need to populate a TreeListView with MyObject elements (Using TreeListView). Also I need one column been filled with .Data property. I can not populate it even as a list(all items on the same level) and without any columns, I've tried this:

this.myTreeListView.SetObjects(list);

and this:

this.myTreeListView.Roots = list;

But the tree is still empty, nothing has been populated, what am I doing wrong ? Please help.


Solution

  • You can find some useful "getting started" information regarding the TreeListView here. Make sure you understand and use that concept.

    However, there is no mention that you also have to add at least one column (you can do this in the designer). So this might be your problem. The TreeListView tutorial assumes that you already know how to use the ObjectListView.

    I suggest you also read the general getting started guide, especially the "mental gear shift" section.

    The crucial part of using an ObjectListView is configuring it. Most of this configuration can be done within the IDE by setting properties on the ObjectListView itself or on the columns that are used within the list. Some configuration cannot be done through properties: these more complex configurations are done by installing delegates (more on this later). Once the columns and control are configured, putting it into action is simple.

    Hope this helps.