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.
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.
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.
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.
Yes please :)
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
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.
Whatever's easiest. VBCodeBook.NET email address
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:
how would I add an image (different for each parent) from an imagelist?VB Code:
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
On this line:
VB Code:
Dim node As New TreeNode(str.Substring(str.IndexOf("\") + 1))
Just add the imageindex from the ImageList to the end
VB Code:
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.
Thanks yet again Edneeis :cool: