TreeNode as ByRef

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aryanbs
    New Member
    • Mar 2009
    • 42

    TreeNode as ByRef

    I was doing some treeNode related work and passed a treenode as a reference(thoug h I could pass a copy of reference using ByVal). And the result was duplicated nodes in TreeView. This is not a problem but I just want to know why it duplicates Node, My code follows, just a treeview and a button is needed in a form. Thanks for help



    Code:
    Option Strict On
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            CheckFromList(TreeView1.Nodes(0))
        End Sub
        Public Shared Sub CheckFromList(ByRef NodetoCheck As TreeNode)
            For Each node2 As TreeNode In NodetoCheck.Nodes
                If node2.Text = "David" Then
                    node2.Checked = True
                End If
            Next
        End Sub
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            TreeView1.CheckBoxes = True
            Dim tn As TreeNode = TreeView1.Nodes.Add("<<Top>>")
            tn.Nodes.Add("David")
        End Sub
    End Class
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    How do you know that the node is duplicated?


    -Frinny

    Comment

    • aryanbs
      New Member
      • Mar 2009
      • 42

      #3
      Frinny!
      First of all thanks for looking into the code, I have posted the sample code which gave me such result. Did you try that? I am using Visual Studio 2008 and working with .Net Framework 3.5

      My above statement
      " just a treeview and a button is needed in a form. Thanks for help"
      Just create a new project and add a treeview and button with their default name and paste my code, If same thing happens whats happening with me, you will surely see what I mean.

      Thanks Again

      Edit: By the way above code is just a sample done in clean project, I got this thing in a big project but making it easier to answerers to get the insight of the problem quickly

      Comment

      • aryanbs
        New Member
        • Mar 2009
        • 42

        #4
        So let go this thread to pass in peace?

        Comment

        Working...