Results 1 to 5 of 5

Thread: [RESOLVED] [2005] Iterate through treenodes

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Resolved [RESOLVED] [2005] Iterate through treenodes

    I'm struggling to work out how to iterate through treenodes. What I've done is programmatically created a TreeView, creating a (DatabaseName) header as follows:

    Code:
    trvDbNameNormal = Me.TreeView1.Nodes.Add("DatabaseName", "Common tables: " & Me.cmbDatabases.Text.ToUpper, 0, 0)
    The children (table names) within this node are created by:

    Code:
    nodeTable = trvDbNameNormal.Nodes.Add(strTable, strTable, 1, 1)
    What I want to do is iterate through these children to perform some SQL on the table names - but I can't figure out how to get the contents of these nodes.
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] Iterate through treenodes


  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: [2005] Iterate through treenodes

    Thanks - but all I keep getting is the Parent, not the Children. How do I get at the children?
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

  4. #4
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2005] Iterate through treenodes

    Did you try that code? It gets every single node in the TreeView.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    May 2006
    Location
    Manchester, England
    Posts
    255

    Re: [2005] Iterate through treenodes

    Sorry - yes - don't know what I did wrong. It does iterate through everything in the tree.

    However, I realised what I was doing wrong on the way home last night! The simple solution was to declare the TreeNode I wanted to use as Private, and iterate through that node. Unfortunately, it shows the text "TreeNode: " and the treenode, but I can handle that.

    Code:
            For Each childNode As TreeNode In trvDbNameNormal.Nodes
    
                MsgBox(childNode.ToString)
    
            Next
    Thanks for your help.
    At home - VB.NET 2005/2008 Express, Visual Web Developer 2005 Express
    At work - VS 2008 Standard (VB)
    .NET 2.0/3.5


    Visual Studio Express Learning Centre | How do I videos | MSDN VB Express Forum | MSDN VB Developer Centre

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