Click to See Complete Forum and Search --> : Adding an image to a parent node in a dynamic Treeview *[RESOLVED]*
RealNickyDude
Jan 28th, 2003, 08:30 AM
What's the correct syntax for adding an image to parent nodes in a Treeview? I have the images ready in an image list, but i'm stuck as to how to add the image at runtime as the list is generated dynamically everytime the program's ran.
Thanks.
Edneeis
Jan 28th, 2003, 12:05 PM
You can pass the index of the image into the constructor of the treenode.
dim nod as New TreeNode("MyText",ImageIndex, SelectedImageIndex)
If you want the image of the node to be the same when it is selected then just pass the same index twice.
Edneeis
Jan 28th, 2003, 12:29 PM
I have a lot fo the client done on the code storage/sharing app I've been working on. If you want I'll post the client code which has some things like loading a treeview dynamically. A lot of the other stuff probably wont help because it is related to the sharing bit, but there could be some stuff that you want to use. Also the loading the treeview currently works off of loading a datatable which I need to change to work with a class instead. So if you want it hten let me know and i'll post it.
RealNickyDude
Jan 28th, 2003, 12:31 PM
Yes please :)
Edneeis
Jan 28th, 2003, 01:50 PM
Here you go. Its the IShareClient. There is still a lot of work that needs to be done to it but the cosmetic stuff is all you really need and that should be done for the most part.
Well it seems the file is too big...I'll post a link in a sec
Edneeis
Jan 28th, 2003, 03:07 PM
Well it seems my server has decided to be problematic today so it'll have to wait until I get home. Or if you want me to email it to you then just give me your email address.
RealNickyDude
Jan 28th, 2003, 03:14 PM
Whatever's easiest. VBCodeBook.NET email address (vbcodebook@madladdesigns.co.uk)
RealNickyDude
Jan 30th, 2003, 08:44 AM
Very impressive! And very complicated!! (for me anyway) I still don't know how to add an image to the parent nodes!
here's the code i'm using to create the treeview:
Private Sub RefreshList()
Try
Dim topics() As String = Directory.GetDirectories("code\")
Dim str As String
TreeView1.ImageList = ImageList1
For Each str In topics
Dim dir As New DirectoryInfo(str)
Dim fi() As FileInfo = dir.GetFiles("*.rtf")
Dim node As New TreeNode(str.Substring(str.IndexOf("\") + 1))
TreeView1.Nodes.Add(node)
Dim f As FileInfo
For Each f In fi
node.Nodes.Add(f.Name.Remove(f.Name.IndexOf("."), 4))
Next
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
how would I add an image (different for each parent) from an imagelist?
Edneeis
Jan 30th, 2003, 10:09 AM
On this line:
Dim node As New TreeNode(str.Substring(str.IndexOf("\") + 1))
Just add the imageindex from the ImageList to the end
Dim node As New TreeNode(str.Substring(str.IndexOf("\") + 1),ImageListIndex,ImageListIndex)
Then whatever you want to use to change that number you do that first.
RealNickyDude
Jan 30th, 2003, 05:33 PM
Thanks yet again Edneeis :cool:
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.