Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to programmatically expand TreeNode that is assigned to a TreeView

I am working with C++ and .NET 1.1. I have an issue with programmatically expanding TreeNode objects once they are assigned to a TreeView. When running the following code in debug mode:

TreeView* myTreeView = new TreeView();
TreeNode* myTreeNode = new TreeNode();
myTreeNode->Expand();
myTreeView->Nodes->Add(myTreeNode);
myTreeNode->Expand();

I can see that the IsExpanded property of myTreeNode is set to true when doing the first Expand(), but when the node is added to myTreeView IsExpanded is set to false, and the second Expand() has no effect at all.

Can anyone explain this behavior? I'm thinking there is a setting for the TreeView or something similar, but I haven't been able to find anything like that, and from the example code MS provides this should work just fine, so I'm probably missing something pretty obvious...

like image 963
Jon Hallin Avatar asked Jan 17 '26 00:01

Jon Hallin


2 Answers

I suggest adding a myTreeNode->Collapse() before calling the expand. It could be that the node thinks it is expanded when it is not and so calling expand will just be ignored because the node thinks it is already expanded anyway...

  TreeView* myTreeView = new TreeView();
  TreeNode* myTreeNode = new TreeNode();
  myTreeNode->Expand();
  myTreeView->Nodes->Add(myTreeNode);
  myTreeNode->Collapse();
  myTreeNode->Expand();
like image 157
Phil Wright Avatar answered Jan 19 '26 16:01

Phil Wright


Have you tried listening for the TreeView.AfterCollapse event to see if someone else is collapsing the TreeNode after you add it to the TreeView?

like image 34
Paul Williams Avatar answered Jan 19 '26 15:01

Paul Williams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!