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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Adding nodes to a treeview control

Adding nodes to a treeview control

Scheduled Pinned Locked Moved Visual Basic
helpdatabasemysqlvisual-studioalgorithms
7 Posts 3 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.
  • R Offline
    R Offline
    Raistlin21_45
    wrote on last edited by
    #1

    Hi, I've been banging my head on the keyboard for a few days now searching for a solution to my problem. Iv'e searched Google for a solution but I can't seem to find any. The node information is stored in a MySQL database using the nodes.fullpath command or like this: lvl1\lvl2\lvl3 Now, I've seen and tried to use the treeview.nodes.add(1).nodes.add(2).nodes.add(3) with a split command but because I don't know how many levels there are before hand this makes a giant select case that makes me cry each time I see it. I want the routine to check if the level exists then add it if it doesn't and/or move to the next level. (Geez it sounds so simple writen like that...) Here is the routine I'm using Dim SQL As String = "Select * from troubleshooting order by node_path asc" Dim StrNodePath As String Dim nNode As TreeNode Dim BolNew As Boolean = True Dim X As Integer Dim StrNode As String RSProbleme = ReturnForm.StrConn.Execute(SQL) Do Until RSProbleme.EOF = True StrNodePath = RSProbleme("node_path").Value aNodePath = Split(StrNodePath, "\") For X = 0 To UBound(aNodePath) BolNew = True For Each nNode In TrVProbleme.Nodes If nNode.Text = aNodePath(X) Then BolNew = False End If Next If BolNew = True Then nNode.Nodes.Add(aNodePath(X)) <-- This is the line that gives me trouble End If Next RSProbleme.MoveNext() Loop When adding it gives me the error, "Object reference not set to an instance of an object." and using the variable watch in VS it says that nNode = Nothing. Any help will be greatly appreciated. (My head hurts from all that banging...) Thanks For every action there is an equal and opposite malfunction

    D H 2 Replies Last reply
    0
    • R Raistlin21_45

      Hi, I've been banging my head on the keyboard for a few days now searching for a solution to my problem. Iv'e searched Google for a solution but I can't seem to find any. The node information is stored in a MySQL database using the nodes.fullpath command or like this: lvl1\lvl2\lvl3 Now, I've seen and tried to use the treeview.nodes.add(1).nodes.add(2).nodes.add(3) with a split command but because I don't know how many levels there are before hand this makes a giant select case that makes me cry each time I see it. I want the routine to check if the level exists then add it if it doesn't and/or move to the next level. (Geez it sounds so simple writen like that...) Here is the routine I'm using Dim SQL As String = "Select * from troubleshooting order by node_path asc" Dim StrNodePath As String Dim nNode As TreeNode Dim BolNew As Boolean = True Dim X As Integer Dim StrNode As String RSProbleme = ReturnForm.StrConn.Execute(SQL) Do Until RSProbleme.EOF = True StrNodePath = RSProbleme("node_path").Value aNodePath = Split(StrNodePath, "\") For X = 0 To UBound(aNodePath) BolNew = True For Each nNode In TrVProbleme.Nodes If nNode.Text = aNodePath(X) Then BolNew = False End If Next If BolNew = True Then nNode.Nodes.Add(aNodePath(X)) <-- This is the line that gives me trouble End If Next RSProbleme.MoveNext() Loop When adding it gives me the error, "Object reference not set to an instance of an object." and using the variable watch in VS it says that nNode = Nothing. Any help will be greatly appreciated. (My head hurts from all that banging...) Thanks For every action there is an equal and opposite malfunction

      D Offline
      D Offline
      digicd1
      wrote on last edited by
      #2

      I am guessing that you created a treeview called TrVProbleme in your application. If you have not added any nodes to the treeview - then nNode will be nothing. You might want to try changeing the statement nNode.Nodes.Add(aNodePath(X)) to TrVProbleme.Nodes.Add(aNodePath(X)) Hope this helps Digicd1

      R 1 Reply Last reply
      0
      • R Raistlin21_45

        Hi, I've been banging my head on the keyboard for a few days now searching for a solution to my problem. Iv'e searched Google for a solution but I can't seem to find any. The node information is stored in a MySQL database using the nodes.fullpath command or like this: lvl1\lvl2\lvl3 Now, I've seen and tried to use the treeview.nodes.add(1).nodes.add(2).nodes.add(3) with a split command but because I don't know how many levels there are before hand this makes a giant select case that makes me cry each time I see it. I want the routine to check if the level exists then add it if it doesn't and/or move to the next level. (Geez it sounds so simple writen like that...) Here is the routine I'm using Dim SQL As String = "Select * from troubleshooting order by node_path asc" Dim StrNodePath As String Dim nNode As TreeNode Dim BolNew As Boolean = True Dim X As Integer Dim StrNode As String RSProbleme = ReturnForm.StrConn.Execute(SQL) Do Until RSProbleme.EOF = True StrNodePath = RSProbleme("node_path").Value aNodePath = Split(StrNodePath, "\") For X = 0 To UBound(aNodePath) BolNew = True For Each nNode In TrVProbleme.Nodes If nNode.Text = aNodePath(X) Then BolNew = False End If Next If BolNew = True Then nNode.Nodes.Add(aNodePath(X)) <-- This is the line that gives me trouble End If Next RSProbleme.MoveNext() Loop When adding it gives me the error, "Object reference not set to an instance of an object." and using the variable watch in VS it says that nNode = Nothing. Any help will be greatly appreciated. (My head hurts from all that banging...) Thanks For every action there is an equal and opposite malfunction

        H Offline
        H Offline
        Hacknight94
        wrote on last edited by
        #3

        hi! have u finish adding nodes to a treeview control? can u help me! can u give me ur code and the code in SQL! i need it badly! i hope u can help me! thanks a lot! coder

        R 1 Reply Last reply
        0
        • D digicd1

          I am guessing that you created a treeview called TrVProbleme in your application. If you have not added any nodes to the treeview - then nNode will be nothing. You might want to try changeing the statement nNode.Nodes.Add(aNodePath(X)) to TrVProbleme.Nodes.Add(aNodePath(X)) Hope this helps Digicd1

          R Offline
          R Offline
          Raistlin21_45
          wrote on last edited by
          #4

          Indeed you are correct; while I did not change the line as you suggested I've added a If... End If checking if this was a root node or not then added your line. (Can't believe it was so simple :mad:grr...) Thanks a bunch!:-D Raist For every action there is an equal and opposite malfunction -- modified at 12:12 Wednesday 10th May, 2006

          1 Reply Last reply
          0
          • H Hacknight94

            hi! have u finish adding nodes to a treeview control? can u help me! can u give me ur code and the code in SQL! i need it badly! i hope u can help me! thanks a lot! coder

            R Offline
            R Offline
            Raistlin21_45
            wrote on last edited by
            #5

            What kind of code are you interested in and what is the purpose?(what is it supposed to do?) Raist For every action there is an equal and opposite malfunction

            H 2 Replies Last reply
            0
            • R Raistlin21_45

              What kind of code are you interested in and what is the purpose?(what is it supposed to do?) Raist For every action there is an equal and opposite malfunction

              H Offline
              H Offline
              Hacknight94
              wrote on last edited by
              #6

              good morning! a code that will retrieve the data from database or using query! i will use the treeview for making a organizational chart! one main ParentNode(Division),childnode(Department) and subchildnode(Section) Thanks for ur kindheart! "Giving something does not reduce what you have but gain more!" coder

              1 Reply Last reply
              0
              • R Raistlin21_45

                What kind of code are you interested in and what is the purpose?(what is it supposed to do?) Raist For every action there is an equal and opposite malfunction

                H Offline
                H Offline
                Hacknight94
                wrote on last edited by
                #7

                Good morning!The code that i will use is all that name in the node that wiil display is came from the database, or using query! i will use it in making organizational chart! the content is i have a parentnode(Division), Chilnode(Department) and SubChildnode(Section). thanks! " Giving something to anyone is not reducing what u have instead you gain more!" coder

                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