Help with List and Tree Views

Trying to learn stuff not covered in class

Page 1 of 1

1 Replies - 1354 Views - Last Post: 10 March 2009 - 05:48 PM Rate Topic: -----

#1 dragonseyeangie  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 41
  • Joined: 20-October 08

Help with List and Tree Views

Post icon  Posted 10 March 2009 - 04:04 PM

Hello,

I am trying to learn how to work with the different controls in Visual Studio for VB.Net in particular the List View and Tree Views.

I looked on the msdn site for help on using these controls before actually posting my question, but it didn't make much sense to me. I don't have any code to show as I am not working on anything in particular just messing around with it to learn what the different controls do that weren't covered in my Intro to VB.Net class last semester.

I would like a clearer explanation on how to actually use code for these controls. In particular adding and removing items from the List and Tree Views using code.

Is This A Good Question/Topic? 0
  • +

Replies To: Help with List and Tree Views

#2 scalt  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 63
  • View blog
  • Posts: 342
  • Joined: 22-November 07

Re: Help with List and Tree Views

Posted 10 March 2009 - 05:48 PM

I'm not sure about ListViews but TreeViews are relatively simple to use after you get to know them.

TreeViews are based on TreeNodes. Each entry in a TreeView is a node, which leads to a lot of nested nodes (ie you add nodes to nodes). You will use TreeNodes quite a bit. Each TreeNode or TreeView has a '.Nodes' property that you use to access any subnodes.

A quick example of some nested tree nodes (hopefully this isn't too complicated):
        'this is our first node (will be the first entry in the TreeView AFTER we add it)
        Dim tn As New TreeNode("Node 1")
        'create two sub-nodes or 'leaves' for Node 1
        tn.Nodes.Add("Node 1.1")
        tn.Nodes.Add("Node 1.2")

        'create another sub-node for Node 1, except this will have more sub-nodes under it
        Dim tn2 As New TreeNode("Node 1.3")
        'create two sub-nodes or 'leaves' for Node 1.3
        tn2.Nodes.Add("Node 1.3.1")
        tn2.Nodes.Add("Node 1.3.2")

        'add Node 1.3 and all its subnodes to Node 1
        tn.Nodes.Add(tn2)

        'add Node 1 to our TreeView (called 'tv' in this case)
        tv.Nodes.Add(tn)



Generally, if you have a lot of nodes with sub-nodes to add, you would set up a 'for' loop (or even some nested 'for' loops) to do this for you.

EDIT:
The '.Nodes' property of a node or treeview is actually a TreeNodeCollection which is KIND OF like (not exactly, but similar to) an array list of nodes. Thus an individual node can be referenced by its index number ie
treeview.Nodes(0)


This post has been edited by scalt: 10 March 2009 - 06:20 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1