By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,359 Members | 1,495 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,359 IT Pros & Developers. It's quick & easy.

VB.net TreeView won't display on my form?

P: 2
Hi all - I'm kind of a newbie. I've been researching this problem for a couple of days now and my searches haven't really come up with any solutions - hopefully I'm just doing something silly and someone will be able to point it out to me!

I'm working with a dataset - which is separated from the rest of the program by a datamanager class I made.

My form calls the datamanager class function that will call the function in the dataset to create a treeview based on the relational data in my dataset.

When the treeview is returned to the original sub that call it in the form I can see that all of the nodes are still intact - but nothing displays on the form?


Here's the code under the form load event:
Dim i As Integer
songTree.Nodes.Clear()
For i = 0 To My.Application.DataManager.getSongTree().Nodes.Cou nt - 1
songTree.Nodes.Add(My.Application.DataManager.getS ongTree().Nodes(i))
Next

songTree.Show()

Here's the code in my dataset:
Public Function gettreenode() As Windows.Forms.TreeView
Dim songTree As New Windows.Forms.TreeView
Dim nodeBand, nodeAlbum, nodeSong As New Windows.Forms.TreeNode
Dim rowBand, rowbandstoalbums, rowAlbum, rowSong As DataRow

For Each rowBand In Me.Tables("Bands").Rows

nodeBand = New Windows.Forms.TreeNode
nodeBand.Text = rowBand("BandName")
nodeBand.Tag = rowBand
nodeBand = songTree.Nodes.Add(rowBand("BandName"))
nodeBand.Tag = rowBand

songTree.Nodes.Add(nodeBand)

For Each rowbandstoalbums In rowBand.GetChildRows("BandAlbumsBand")
rowAlbum = rowbandstoalbums.GetParentRow("AlbumBandsAlbums")

nodeAlbum = nodeBand.Nodes.Add(rowAlbum("AlbumTitle"))
nodeAlbum.Tag = rowAlbum
nodeBand.Nodes.Add(nodeAlbum)

For Each rowSong In rowAlbum.GetChildRows("SongsAlbums")
nodeSong = nodeAlbum.Nodes.Add(rowSong("SongTitle"))
nodeSong.Tag = rowSong
nodeAlbum.Nodes.Add(nodeSong)

Next
Next
Next

Return songTree
End Function

Any ideas?
Thanks!
Apr 14 '07 #1
Share this Question
Share on Google+
3 Replies


iburyak
Expert 100+
P: 1,017
I didn't test it but do you have something like tree.refresh property?

Sometimes Microsoft tree nodes disappear but it is enough to move scrollbar up and down for them to show up again.
Apr 15 '07 #2

P: 2
I've tried

tree.refresh
tree.visible = true


neither have any effect....
Apr 15 '07 #3

iburyak
Expert 100+
P: 1,017
Step through your code again it looks to me that function gettreenode loads tree directly and you donít need to load it again in form load.

Use songTree.Show() before load it might help visualize on what is going on. You can remove this after itíll start working as intended.

With a loop below you duplicate each node that already loaded by a function. Maybe it is better just to pass a tree as an object to your function and load it as you do but once.

Expand|Select|Wrap|Line Numbers
  1. For i = 0 To My.Application.DataManager.getSongTree().Nodes.Count - 1
  2.    songTree.Nodes.Add(My.Application.DataManager.getSongTree().Nodes(i))
  3. Next
  4.  
Maybe I am wrong, it is hard to judge without testing.

Good Luck.
Apr 15 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.