Home > Blockchain >  C# ObjectListView TreeListView add multi-level Nodes
C# ObjectListView TreeListView add multi-level Nodes

Time:03-03

I'm using ObjectListView.Official.2.9.1.nupkg
enter image description here

Other using this Nuget package, can i do this with only using System.Windows.Forms.ListView?
*A TreeView list with columns.

CodePudding user response:

You should be able to do this in the same way that you added the first child to the first parent.
Create the instance of the node, then add it to the parent, and add other nodes to it... Should be something like this:

private void InitializeData()
{
    // create fake nodes
    var parent1 = new Node("PARENT1", "-", "-", "-");
    var child1 = new Node("CHILD_1_1", "A", "X", "1");
    parent1.Children.Add(child1);
    var childChild1 = new Node("CHILD_1_1_CHILD", "T", "R", "45");
    child1.Children.Add(childChild1);
    parent1.Children.Add(new Node("CHILD_1_2", "A", "Y", "2"));
    parent1.Children.Add(new Node("CHILD_1_3", "A", "Z", "3"));

    var parent2 = new Node("PARENT2", "-", "-", "-");
    parent2.Children.Add(new Node("CHILD_2_1", "B", "W", "7"));
    parent2.Children.Add(new Node("CHILD_2_2", "B", "Z", "8"));
    parent2.Children.Add(new Node("CHILD_2_3", "B", "J", "9"));

    var parent3 = new Node("PARENT3", "-", "-", "-");
    parent3.Children.Add(new Node("CHILD_3_1", "C", "R", "10"));
    parent3.Children.Add(new Node("CHILD_3_2", "C", "T", "12"));
    parent3.Children.Add(new Node("CHILD_3_3", "C", "H", "14"));

    data = new List<Node> { parent1, parent2, parent3 };
}
  • Related