Search code examples
c#objectlistviewtreelistview

TreeListView programmatically expand node after adding child


I use this code to add a child to a BrightIdeasSoftware TreeListView node:

var br = treeListView1.TreeModel.GetBranch(treeListView1.SelectedObject);
((Node)br.Model).Children.Add(new Node(...));
treeListView1.RefreshObject(br.Model);

However, when I try to expand the branch after the above code:

br.Expand();

I get the following error:

Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.

Any help with this error?


Solution

  • This worked for me:

    treeListView1.Expand(br.Model);