Results 1 to 13 of 13

Thread: Name Nodes from Array

  1. #1

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Name Nodes from Array

    I have an array (tvw_Nodes) that I would now like to use to add to a treeview as the names of the nodes.
    These nodes would be childnodes, and then I have a second array (tvw_ChildNodes) which would be the ... hmm... grandchild Nodes??

    How do I go about taking the elements from the array and adding them to the treeview?

    I tried something like this but I get the error "Index out of bounds":

    vb Code:
    1. With Treeview
    2.     For Ctr = 0 To Ubound(MyArray)
    3.         .Nodes(ctr).Text = MyArray(ctr)
    4.     Next
    5. End With

    This is all done in the Form_Load()
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Name Nodes from Array

    Before you can access a treeview node's property, the node has to exist or was already added to the treeview's nodes collection. Also, how do you intend to relate the grandchild nodes? Do they all fall under one child node?

  3. #3

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Name Nodes from Array

    The attached document show what I am trying to achieve.

    At the moment I am loading it all from the form_load, by code,

    vb Code:
    1. tvwCode.Nodes.Add "One", tvwChild, "API", "API", "Folder Closed"

    but I am trying to get it so I load the node names from a database, then add the nodes required.
    I am tring to do it this way, so in the future the user can add a node, that new node would be stored in the database, and then, the next time the app is run, it would have the new node as well.

    I hope you can understand this.
    Attached Files Attached Files
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  4. #4

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Name Nodes from Array

    The grandchild nodes fall under different childnodes.

    I have tried this and now get "Element not found" EDIT This now works, or should I say goes through the code, but still doesn't show any new nodes on the treeview.

    vb Code:
    1. Private Sub Command1_Click()
    2. Dim ctr As Integer
    3. With TreeView1
    4.    
    5.     For ctr = 0 To UBound(MyNodes)
    6.         .Nodes.Add "Main", tvwChild, "Num " & ctr, MyNodes(ctr)  <------here
    7.     Next
    8. End With
    9.  
    10. End Sub

    I have also added code to set the first node before this code..

    vb Code:
    1. TreeView1.Nodes.Add , , "Main", "Numbers"

    the array's elements are all loaded correctly as well.
    Last edited by aikidokid; Mar 8th, 2007 at 11:17 AM.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Name Nodes from Array

    Storing node names is not enough. You also have to store level and parent-child relationship of the nodes.

  6. #6

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Name Nodes from Array

    So, if I am storing the names of the nodes in a database, then I would have to sore this is another field, or in the same, but split the string when loaded into the array?
    possibly a two dimentional array?
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  7. #7
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Name Nodes from Array

    What are the fields in the database, and how are your retrieving the info from the database (eg. how come you ended up with an array instead of a recordset)

  8. #8
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Name Nodes from Array

    TreeView1.Nodes.Add accepts the following arguments
    -relative
    -relationship
    -key
    -text

    It would be best to store those values in the database (in separate fields), so when setting up the treeview again you just plugin the stored values.

  9. #9

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Name Nodes from Array

    ahh (I think)

    So instead of storing just
    "VB Code"
    in the array, store
    "Main", tvwChild, "VBCode", "VB Code"

    Is this what you mean?
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  10. #10
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Name Nodes from Array

    Relative is an index value, not string.

    When storing (and your using the child relationship and the node has a parent), relative field = node.Parent.Index

    Above implies that you will have to store/process your root level nodes differently (since they have no parents). For these nodes, store relative = 0 in DB. When setting up the treeview from recordset, if rs.Fields("relative").Value = 0 then leave that argument blank ...

    TreeView1.Nodes.Add , tvwLast, rs.Fields("Key").Value & "", rs.fields("NodeName").Value & "".

    Else if relative > 0 then pass all values (relative, relationship, key, text) from recordset

  11. #11

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Name Nodes from Array

    Thanks leinad31, I will give this a go tomorrow and let you know how I get on

    I am sure there will be more questions to follow
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  12. #12

    Thread Starter
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: Name Nodes from Array

    Quote Originally Posted by leinad31
    What are the fields in the database, and how are your retrieving the info from the database (eg. how come you ended up with an array instead of a recordset)
    This is an excellent question, and the answer is ......
    I am only just starting out with databases, so I assumed I had to store the retrieved data frm the DB into an array to use afterwards.

    I also have to learn how to set up my database as well.
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  13. #13
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Name Nodes from Array

    Don't forget to include a primary key (use autonum) in addition to the fields your using to maintain the nodes.

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