Results 1 to 7 of 7

Thread: [RESOLVED] Adding nodes to a TreeView

  1. #1

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211

    Resolved [RESOLVED] Adding nodes to a TreeView

    I need to be able to add nodes to a treeview at runtime but I dont know how many I need to add before I run the program. Here is what happends, I read a txtfile then I certain info from that textfile and then I need to add the info into a treeview. I have the first part working fine but im not sure how to add the strings to a treeview here is the code im using now
    vb Code:
    1. Dim root1 As TreeNode = New TreeNode("root1Text")
    2.         Dim root2 As TreeNode = New TreeNode("root2Text")
    3.         Dim sub1 As TreeNode = New TreeNode("sub1Text")
    4.         Dim sub2 As TreeNode = New TreeNode("sub2Text")
    5.         TVOpen.Nodes.Add(root1)
    6.         TVOpen.Nodes.Add(root2)
    7.         root1.Nodes.Add(sub1)
    8.         root1.Nodes.Add(sub2)

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Adding nodes to a TreeView

    That code works. What's the problem? You know how to add a string to a TreeView. Do you know how to read a text file? If so then you already know everything you need. Just loop through the lines of the text file and add each to the tree.

  3. #3

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211

    Re: Adding nodes to a TreeView

    Well it works but how would I loop through it so I dont have to make a million variables? At the moment it only adds 2 nodes, how would i add multiple nodes with differnt strings.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Adding nodes to a TreeView

    Are you saying that you don't know how to loop through an array or collection of strings?

  5. #5

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211

    Re: Adding nodes to a TreeView

    Yea.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: Adding nodes to a TreeView

    That's a bit of a worry.
    vb Code:
    1. For Each str As String In myArrayOrCollection
    2.     'Use str here.
    3. Next str

  7. #7

    Thread Starter
    Frenzied Member Motoxpro's Avatar
    Join Date
    Sep 2001
    Location
    Spiro, OK
    Posts
    1,211

    Re: Adding nodes to a TreeView

    Ah, thanks. Just one more thing when im reading my textfile how can i get all the text between to variables. Say i wanted all the text inbetween the title and a new line:

    title=Hello
    text here

    title=Nice Day
    text here

    title=Awesome
    text here

    title=Sweet
    text here

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