Skip to main content

Treeview Structure in VB.Net

In this post, we will look at how the Treeview can be used.

I am using Visual Basic 2008 Express Edition.

In one of my earlier posts, I had explained in detail about Treeview in Excel-VBA. Through this post, I would like to bring the VB.Net way of the control.



1) get the Control:

From the Toolbox (Common Controls tab), drag the treeview onto your form.
For convenience, I have named it - TV.

2) Build the Tree up:

You build tree by adding nodes as child of another Node (or as a child of the TV).

Special things to note for a Node.

You can specify an image for a Node.

You can attach an Object to each Node through the TAG property of the Node. This is something which I found really useful.

Node Object : TreeNode

Adding a node:

You can add a node to the TV.

'--- Start ---
Dim iNode As New TreeNode
Dim iObj as New MyObject

'Define iObj...

iNode.Name = "Name1"
iNode.Text = "Root Node 1"
iNode.Tag = iObj

TV.Nodes.Add(iNode)

'--- End ---


Or You can add a node to an existing Node.

'--- Start ---
Dim iNode As New TreeNode
Dim pNode as TreeNode
Dim iObj as New MyObject

'Define iObj...

pNode = TV.Nodes(0) 'Zero is the index of the Node at that Level.

iNode.Name = "Name2"
iNode.Text = "Child Node 1"
iNode.Tag = iObj

pNode.Nodes.Add(iNode)

'--- End ---



Removing a node:

TV.Nodes(0).Nodes(0).Remove()

or

iNode = TV.SelectedNode 'or Get the Node of the TV as an Object.
iNode.Remove()




Clearing all nodes:

TV.Nodes.Clear()





3. Usual properties of Nodes:

You can refer to a node with its Index.

'Gets or sets the Text
TV.Nodes(i).Text

'Gets or sets the Name of the Node
TV.Nodes(i).Name

'say iNode = TV.Node(0).Nodes(2)

'Gets the Index of the Node at that Level.
iNode.Index

'Gets the No of children the has got.
iNode.Nodes.Count

'Gets the First Child Node and the Last Child Node
iNode.FirstNode
iNode.LastNode

etc....



more, later some time...

Comments

Popular posts from this blog

TreeView Structure in Excel VBA

TreeView is extreamly useful in specific cases but it can be bit tricky sometimes to implement.  Last Few days I was working on a TreeView Structure and thought I will share the knowledge I gained...  This post takes you through the basic operations to create and operate a TreeView. It will be like the Folder tree window of the windows explorer.  Moreover, you can have it dynamically updated based on the data in excel.... Here we go..

Controlling LED through Octolapse for 3D print timelapse

Today's post is about one of the 3D Printing adaptation that I learned. This is specifically about how to control an LED light automatically through OctoLapse so that it is switched on only when the timelapse photo is taken. Just as a background, I have been learning to use 3D printer and its customizations options for a few months now and was a lot of learning since then. The best thing was OctoPi, a platform for controlling the 3D printer and the many plugin options that are developed by the community.  Most of them are like open source. Today we will discuss specifically about an adaptation to one such plugin, OctoLapse. OctoLapse is the plugin for taking timelapse photos, with many options for further customisations. One of the best timelapse method is taking photo after each layer is complete, by moving the head out of the way. You can use standard Pi Camera or a DSLR, which is great to get good resolution videos. One small flash back before we dive into the topic.  I keep the

Excel Function :TABLE

Its been a while since I have done some posting. This option in excel is something which I thought would be very useful for many. Its the TABLE Function in MS Excel. This is especially useful in the following scenarios.