Databound TreeView with List of List

511 views Asked by At

I'm trying to get some hierarchical object structure into a Winforms TreeView (or some 3rd party treeview). Of course I could just build it node by node but I need to have it databound, so that I don't have to take care of a user adding some node(s) to the TreeView. My highest priority is to have data consistency between the data (represented by the Enumerable) and the TreeView as a GUI component. If I change the List I want to get the tree updated and inserting Nodes into the tree the other way round.

My structure looks like this:

List<sourcelist> lists = new List<sourcelist>()
            {
                new sourcelist() {
                    name = "List1", 
                    items = new List<item>()
                {
                    new item() {source_key = "abc", name = "Pete"},
                }},
                new sourcelist() {
                    name = "List2"
                },
                new sourcelist() {
                    name = "List3", 
                    items = new List<item>()
                {
                    new item() {source_key = "y0h5l2VsrL", name = "Lisa"},
                    new item() {name = "Kara"},
                }}
            };

Basically some sourcelists that have a name an contain a list of items that have a name and a key

A lot of recommendations leaded me to ObjectListView but I'm also open for better solutions.

I tried to it like this:

        //dataTreeListView1.ParentKeyAspectName = "pid";
        //dataTreeListView1.KeyAspectName = "id";
        dataTreeListView1.RootKeyValue = 0;

        dataTreeListView1.SetObjects(lists);

The tree just remains empty. I think the major problem is that I can't set KeyAspectName and ParentKeyAspectName which would build up the tree's hierarchy.

I also tried to flatten the list and give it a structure with id and ParentId but didn't work out. Also my attempt inserting the List into a DataSet and binding this failed.

Help with this issue would really be appreciated.

0

There are 0 answers