Page 1 of 1

Adding child nodes to treeview programmatically

Posted: Thu Apr 15, 2021 8:17 am
by JaimeBou
I am trying to programmatically add child nodes under a root treeview control.

The nodes do appear, but not as child nodes.

I have looked at some of the demo files provided in this forum and just can't seem to figure out what I am missing.

I could not figure out how to use the select code feature so I added the sample code as an attachment.

Can you help me please.

Re: Adding child nodes to treeview programmatically

Posted: Thu Apr 15, 2021 3:01 pm
by jvierra
Each "node" has a "Nodes" property which is where to place children of a node.

Here is one good example:

Re: Adding child nodes to treeview programmatically

Posted: Thu Apr 15, 2021 3:08 pm
by jvierra
The following tutorial will help you to learn how to use the TreeView control which is one of the most complex controls in the toolbox and is always a challenge for anyone who has limited or no experience with WinForms. Take time and try all of the example code until you understand what the control does and how MS designed it to be used.

The following is the MSDN documents and description: https://docs.microsoft.com/en-us/dotnet ... mework-4.8
This is the Sapien PowerShell version: https://info.sapien.com/index.php/guis/ ... ew-control

Re: Adding child nodes to treeview programmatically

Posted: Mon Apr 19, 2021 8:47 am
by JaimeBou
Thanks for your response.

I actually did study this control and viewed your demo file and the sapien treeview control documentation prior to posting.

The link that you provided and the additional information regarding each node having its own node was the key (treeView1.Nodes[0].Nodes.Add("Child 1");).

I may have missed it, but I didn't see this information in the sapien treeview control document.

I modified my code to: $newNode = $WS_TV_SRM_BCAWEB.Nodes[0].Nodes.Add($DataElement.ws) and that solved it.

Thank you.

Re: Adding child nodes to treeview programmatically

Posted: Mon Apr 19, 2021 11:53 am
by jvierra
I know it is not explicit but "tree" means nodes within nodes. It is an old structural reference meaning that things are arranged in a hierarchy that branches. Also the MSDN documentation is always where to go for detailed information about all controls as there are all properties and methods listed with examples.

Glad you got it working. The TV is one of the more challenging controls even for experienced programmers so take your time.