Results 1 to 10 of 10

Thread: Adding an image to a parent node in a dynamic Treeview *[RESOLVED]*

  1. #1

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435

    Thumbs up Adding an image to a parent node in a dynamic Treeview *[RESOLVED]*

    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.
    Last edited by RealNickyDude; Jan 30th, 2003 at 06:33 PM.
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  2. #2
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  4. #4

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    Yes please
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  5. #5
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.

  7. #7

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    Whatever's easiest. VBCodeBook.NET email address
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  8. #8

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435

    Unhappy

    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:

    VB Code:
    1. Private Sub RefreshList()
    2.         Try
    3.             Dim topics() As String = Directory.GetDirectories("code\")
    4.  
    5.             Dim str As String
    6.             TreeView1.ImageList = ImageList1
    7.  
    8.             For Each str In topics
    9.                 Dim dir As New DirectoryInfo(str)
    10.                 Dim fi() As FileInfo = dir.GetFiles("*.rtf")
    11.  
    12.                 Dim node As New TreeNode(str.Substring(str.IndexOf("\") + 1))
    13.                 TreeView1.Nodes.Add(node)
    14.  
    15.                 Dim f As FileInfo
    16.  
    17.                 For Each f In fi
    18.                     node.Nodes.Add(f.Name.Remove(f.Name.IndexOf("."), 4))
    19.                 Next
    20.             Next
    21.         Catch ex As Exception
    22.             MessageBox.Show(ex.Message)
    23.         End Try
    24.  
    25.     End Sub
    how would I add an image (different for each parent) from an imagelist?
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

  9. #9
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    On this line:
    VB Code:
    1. Dim node As New TreeNode(str.Substring(str.IndexOf("\") + 1))

    Just add the imageindex from the ImageList to the end
    VB Code:
    1. 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.

  10. #10

    Thread Starter
    Hyperactive Member RealNickyDude's Avatar
    Join Date
    Nov 2002
    Location
    Watching you through the hidden camera :o
    Posts
    435
    Thanks yet again Edneeis
    [vbcode]
    On Error GoTo Hell
    [/vbcode]:¬) Nicky : Why not try VBCodebook.NET.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width