Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Iterate through child treenodes

Iterate through child treenodes

Scheduled Pinned Locked Moved Visual Basic
databasetutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    penguin5000
    wrote on last edited by
    #1

    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: trvDbNameNormal = Me.TreeView1.Nodes.Add("DatabaseName", "Common tables: " & Me.cmbDatabases.Text.ToUpper, 0, 0) The children (table names) within this node are created by: 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.

    M 1 Reply Last reply
    0
    • P penguin5000

      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: trvDbNameNormal = Me.TreeView1.Nodes.Add("DatabaseName", "Common tables: " & Me.cmbDatabases.Text.ToUpper, 0, 0) The children (table names) within this node are created by: 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.

      M Offline
      M Offline
      MidwestLimey
      wrote on last edited by
      #2

      The TreeNodesCollection class has an indexer so you can access each Node by trvDbNameNormal(0) or trvDbNameNormal(strTable) . The TreeNode class has a Text property which will return strTable name in the case of your code. Then simply write a recursive algorithm to walk the tree. something like:

      Private Sub walkTree(t as TreeNode)
      For i as Integer = 0 To T.Nodes.Count -1
      ' Do something usefull here
      walkTree(T.Nodes(i))
      Next
      End Sub


      I'm largely language agnostic


      After a while they all bug me :doh:


      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups