Connecting Tech Pros Worldwide Help | Site Map

TreeNode as ByRef

Member
 
Join Date: Mar 2009
Location: Kathmandu
Posts: 42
#1: Mar 7 '09
I was doing some treeNode related work and passed a treenode as a reference(though 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



Expand|Select|Wrap|Line Numbers
  1. Option Strict On
  2. Public Class Form1
  3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.         CheckFromList(TreeView1.Nodes(0))
  5.     End Sub
  6.     Public Shared Sub CheckFromList(ByRef NodetoCheck As TreeNode)
  7.         For Each node2 As TreeNode In NodetoCheck.Nodes
  8.             If node2.Text = "David" Then
  9.                 node2.Checked = True
  10.             End If
  11.         Next
  12.     End Sub
  13.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  14.         TreeView1.CheckBoxes = True
  15.         Dim tn As TreeNode = TreeView1.Nodes.Add("<<Top>>")
  16.         tn.Nodes.Add("David")
  17.     End Sub
  18. End Class
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,066
#2: Mar 9 '09

re: TreeNode as ByRef


How do you know that the node is duplicated?


-Frinny
Member
 
Join Date: Mar 2009
Location: Kathmandu
Posts: 42
#3: Mar 11 '09

re: TreeNode as ByRef


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
Member
 
Join Date: Mar 2009
Location: Kathmandu
Posts: 42
#4: Mar 23 '09

re: TreeNode as ByRef


So let go this thread to pass in peace?
Reply