'Talking about my findings and failure to discover what I wanted

Delving deeper into Windows Form, in which I've been using for a little over half a year, I began to use newer objects such as Tree View. This became an obstacle in my project, impeding further progress by hours due to the lack of knowledge of this particular object. So far, I've seen countless discussions and videos of creating nodes for Tree View and whatnot, but still have not found what I was looking for.

'Is this possible?

I want to use Tree View as something similar to a list box, which I used instead of List View because it's basically the simplest list in Windows Forms (currently learning more about list view and tree view objects). This time, I used Tree View in place of list box to have it change labels, add images, videos, and other objects (as such, I have done so by using list box, but tree view fits what I had in mind a lot better and would also save me hundreds of lines of code - figured after I had replaced the list box and the code along with it - as to why, because it was a list within a list which is pretty much a tree view in that aspect).

'What I planned on doing

If my tree view has a parent node, let's say 'Numbers,' then inside of Numbers consists of children called '1, 2, and 3.'

When child node, 1, is selected/clicked on, then label will display "Numbers - 1" (shows directory/path of list) and invisible objects will then be visible. - Likewise, if 2 is selected, the label will display "Numbers - 2" and other objects will change as a result of the click event.

'What I have created (still an example, no code, just TreeView object and its nodes)


If you have tried this before or know how to do this, please let me know. Furthermore, if you attempt this, please show me what you have tried, thanks!

Some things I tried

  • Looking for any possible methods to enable this

  • Contain method. If SelectedNode = "1" Then change Label.Text

Haven't tried

  • Would element selection work?

p = parent c = child (p, c) (0, 1) - Like an array, 0 would be the first element, and 1 would be child node 2.

  • CheckBox (property in TreeView that makes Tree View nodes have checkboxes next to them), something I didn't want, but may end up using if necessary

1 Answers

Community On Best Solutions

This is how you can make a TreeView node control properties of other objects.

Making TreeView node change text of a label:

TreeView1.SelectedNode.Text = Label1.Text

Likewise, you can control other events when a node is selected, by:

If TreeView1.SelectedNode.Text = "Colors" Then
   Label1.Text = "Colors: Red, Green, Blue"
   PictureBox1.Image = My.Resources.RGB ' Shows image of primary colors: Red, Green, Blue
End If

Pretty much what I wanted... Spent probably 6 hours looking for how to implement this into my program. It would've taken at least 5 minutes to look for this. Anyways, hope this helps someone!