469,898 Members | 2,248 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

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

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
3 1612
iburyak
1,017 Expert 512MB
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
WISara
2
I've tried

tree.refresh
tree.visible = true


neither have any effect....
Apr 15 '07 #3
iburyak
1,017 Expert 512MB
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.

Similar topics

42 posts views Thread by lauren quantrell | last post: by
reply views Thread by BjŲrn Bengtsson | last post: by
2 posts views Thread by Irishmaninusa | last post: by
6 posts views Thread by Jarod_24 | last post: by
5 posts views Thread by david | last post: by
9 posts views Thread by auntiejack56 | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.