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. Treeview duplicating nodes

Treeview duplicating nodes

Scheduled Pinned Locked Moved Visual Basic
questioncsharpdata-structureshelp
5 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.
  • G Offline
    G Offline
    garfield185
    wrote on last edited by
    #1

    Hi all. I've got a problem. I'm developing an app on VB.NET, and using a treeview control. I need to check which of all the nodes on the treeview are marked with the checkbox, and it impossible to know how many of them there are, or how deep the tree goes on the nodes level, so I have developed a recursive function, that receives the node as a parameter. It works fine, and makes what I need. The problem is that every time I make this operation, the nodes seem to duplicate in the treeview, although it is only visually, because when I check treeview.nodes.count property, it says there are only the number of nodes I had at the beggining. I have developed a simple app with just a treeview and a button to make this operation, and it still seems to happen so I'm becoming quite desperate. Does somebody know why does it happens?? If someone needs to see the example, I can send it by email. Thanks.

    Time to come clean... Vive y deja vivir / Live and let live Javier

    J 1 Reply Last reply
    0
    • G garfield185

      Hi all. I've got a problem. I'm developing an app on VB.NET, and using a treeview control. I need to check which of all the nodes on the treeview are marked with the checkbox, and it impossible to know how many of them there are, or how deep the tree goes on the nodes level, so I have developed a recursive function, that receives the node as a parameter. It works fine, and makes what I need. The problem is that every time I make this operation, the nodes seem to duplicate in the treeview, although it is only visually, because when I check treeview.nodes.count property, it says there are only the number of nodes I had at the beggining. I have developed a simple app with just a treeview and a button to make this operation, and it still seems to happen so I'm becoming quite desperate. Does somebody know why does it happens?? If someone needs to see the example, I can send it by email. Thanks.

      Time to come clean... Vive y deja vivir / Live and let live Javier

      J Offline
      J Offline
      Jon_Boy
      wrote on last edited by
      #2

      Just guessing that it's something in the recursive function. Go ahead and post your code so we can see it. If needed, make a generic example with your code to reproduce the problem and to be concise. It's better to post the code here rather than send email so that others can possibly learn.

      Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

      G 1 Reply Last reply
      0
      • J Jon_Boy

        Just guessing that it's something in the recursive function. Go ahead and post your code so we can see it. If needed, make a generic example with your code to reproduce the problem and to be concise. It's better to post the code here rather than send email so that others can possibly learn.

        Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

        G Offline
        G Offline
        garfield185
        wrote on last edited by
        #3

        I'm sorry!! Here is the code. I just created a Windows VB.NET application, and put on it a treeview named TreeView1 and a button named Button1. Also, insert some random nodes on the treeview, doesn't matter, because all will appear duplicated. The recursive function is Recorre, as you can see, this function will read all the nodes on the treeview, but won't write anything on it, so, it is so weird for me when I get all the data duplicated. Imports System.Windows.Forms Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TreeView1.ExpandAll() End Sub Private Sub Recorre(ByRef Nodo As TreeNode) Dim i As Integer For i = 0 To Nodo.Nodes.Count - 1 Recorre(Nodo.Nodes(i)) Next End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer Dim TreeView2 As TreeView TreeView1.BeginUpdate() For i = 0 To TreeView1.Nodes.Count - 1 Recorre(TreeView1.Nodes(i)) Next TreeView2 = New TreeView TreeView2 = TreeView1 Me.Controls.Remove(TreeView1) TreeView1 = Nothing TreeView1 = New TreeView Me.Controls.Add(TreeView1) TreeView1.Width = 176 TreeView1.Height = 242 TreeView1.Top = 12 TreeView1.Left = 12 TreeView1.CheckBoxes = True TreeView1.Refresh() TreeView1.EndUpdate() TreeView1 = TreeView2 End Sub End Class

        Time to come clean... Vive y deja vivir / Live and let live Javier

        J 1 Reply Last reply
        0
        • G garfield185

          I'm sorry!! Here is the code. I just created a Windows VB.NET application, and put on it a treeview named TreeView1 and a button named Button1. Also, insert some random nodes on the treeview, doesn't matter, because all will appear duplicated. The recursive function is Recorre, as you can see, this function will read all the nodes on the treeview, but won't write anything on it, so, it is so weird for me when I get all the data duplicated. Imports System.Windows.Forms Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TreeView1.ExpandAll() End Sub Private Sub Recorre(ByRef Nodo As TreeNode) Dim i As Integer For i = 0 To Nodo.Nodes.Count - 1 Recorre(Nodo.Nodes(i)) Next End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer Dim TreeView2 As TreeView TreeView1.BeginUpdate() For i = 0 To TreeView1.Nodes.Count - 1 Recorre(TreeView1.Nodes(i)) Next TreeView2 = New TreeView TreeView2 = TreeView1 Me.Controls.Remove(TreeView1) TreeView1 = Nothing TreeView1 = New TreeView Me.Controls.Add(TreeView1) TreeView1.Width = 176 TreeView1.Height = 242 TreeView1.Top = 12 TreeView1.Left = 12 TreeView1.CheckBoxes = True TreeView1.Refresh() TreeView1.EndUpdate() TreeView1 = TreeView2 End Sub End Class

          Time to come clean... Vive y deja vivir / Live and let live Javier

          J Offline
          J Offline
          Jon_Boy
          wrote on last edited by
          #4

          I don't get a duplication of nodes, I don't get any nodes back on treeview1. It would appear that your temp. clearing the nodes in treeview1 and then readding them? Having said that, I would do several things different. Instead of completely getting rid of treeview1 and readding it to the form and setting its properties, just clear the nodes (treeview1.nodes.clear). Probably don't need to create a whole another treeview to store the nodes (seems overkill), could use a treenodecollection instead. Again, I'm not sure what this is supposed to do other than restore the nodes?

          Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

          G 1 Reply Last reply
          0
          • J Jon_Boy

            I don't get a duplication of nodes, I don't get any nodes back on treeview1. It would appear that your temp. clearing the nodes in treeview1 and then readding them? Having said that, I would do several things different. Instead of completely getting rid of treeview1 and readding it to the form and setting its properties, just clear the nodes (treeview1.nodes.clear). Probably don't need to create a whole another treeview to store the nodes (seems overkill), could use a treenodecollection instead. Again, I'm not sure what this is supposed to do other than restore the nodes?

            Any suggestions, ideas, or 'constructive criticism' are always welcome. "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

            G Offline
            G Offline
            garfield185
            wrote on last edited by
            #5

            It seems to be a problem when sending the node byref, using byval I don't get the error... O_o So, the code could be just like this: Imports System.Windows.Forms Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TreeView1.ExpandAll() End Sub Private Sub Recorre(ByVal Nodo As TreeNode) Dim i As Integer For i = 0 To Nodo.Nodes.Count - 1 Recorre(Nodo.Nodes(i)) Next End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim i As Integer For i = 0 To TreeView1.Nodes.Count - 1 Recorre(TreeView1.Nodes(i)) Next End Sub End Class

            Time to come clean... Vive y deja vivir / Live and let live Javier

            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