Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact
A1VBCode Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      

Home » .NET Programming » Visual Basic .NET » Treeview Tutorial


Treeview TutorialExpand / Collapse
Author
Message
Posted 6/8/2005 12:23:01 PM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: 4/13/2009 1:04:38 PM
Posts: 910, Visits: 5,436
Does anyone know or a REAL tutorial on Treeview. Not loading ado, xml, directories, etc. I mean one that explains the properties of the Treeview control. The above is about all I can find on the internet.

What I am trying to do is add a node to the treeview in a predetermined location. I then want to add two sub-nodes to the one just entered.

Dim oNode As New TreeNode

oNode.Name = "Level1"

TreeView1.Nodes.Add(oNode)

TreeView1.SelectedNode.Name = oNode.Name ==> Getting error here

TreeView1.Nodes.Add("Level1a")

TreeView1.Nodes.Add("level1b")

oNode = Nothing

The error is "NullReferencException was unhandeled." and "Object reference not set to an instance of an object."

Any tutorial on this subject would be greatly appreciated.



Wayne

I know enough to be dangerious.

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.

Post #12026
Posted 6/8/2005 6:25:25 PM
Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Today @ 10:38:55 AM
Posts: 1,000, Visits: 7,782

I don't know of any tutorials and I'm just shooting in the dark here but I would try

TreeView1.SelectedNode = oNode
or
Set TreeView1.SelectedNode = oNode

Post #12029
Posted 6/8/2005 8:29:31 PM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: 4/13/2009 1:04:38 PM
Posts: 910, Visits: 5,436

Thanks Mark but it put all them on the same level. I used:

            oNode.Name = "Level1"
            oNode.Text = "Level1"
            TreeView1.Nodes.Add(oNode)
            TreeView1.SelectedNode = oNode
            oNode = New TreeNode
            oNode.Name = "Level1b"
            oNode.Text = "Level1b"
            TreeView1.Nodes.Add(oNode)
            oNode = New TreeNode
            oNode.Name = "Level1a"
            oNode.Text = "Level1a"
            TreeView1.Nodes.Add(oNode)

 

I appreciate it though.

 



Wayne

I know enough to be dangerious.

It is hard to understand how a cemetery can raise its burial rates and blame it on the cost of living.

Post #12031
Posted 6/9/2005 4:55:13 AM
Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: 3/13/2006 2:34:13 AM
Posts: 794, Visits: 338

Private Sub button2_Click(sender As Object, _
e As System.EventArgs) Handles button2.Click
Dim oNode As New TreeNode
oNode.Text = "My Node"
TreeView1.Nodes.Add(oNode)
oNode.Nodes.Add("")
end sub

Private Sub button1_Click(sender As Object, _
e As System.EventArgs) Handles button1.Click
If treeView1.SelectedNode.IsExpanded Then
treeView1.SelectedNode.Collapse()
MessageBox.Show(treeView1.SelectedNode.Text & _
" tree node collapsed.")
Else
treeView1.SelectedNode.Expand()
MessageBox.Show(treeView1.SelectedNode.Text & _
" tree node expanded.")
End If
End Sub


I haven't done anything w/treeviews yet, but I've pieced the code from yours and msdn and here's a link for taking further steps:
http://www.vbdotnetheaven.com/Code/Jun2003/2083.asp

also, i'm thinking that it's not really neccessary to get Name properties, just use the text properties or hide info in the tag of node you add, then reference that node's tag or text from treevies selectednode event.

prob didn't help much.
good luck







Post #12042
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 1 (1 guest, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Admin, Mod

PermissionsExpand / Collapse

All times are GMT -5:00, Time now is 3:27pm