Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb_dotnet thread: Cannot add node to treeview from another form why??


Message #1 by "Gabriel Brienza" <vbnetuk@y...> on Wed, 27 Feb 2002 14:37:50
I have the following problem

I WANT TO ALLOW A USER TO ADD A NODE

I have the following tree
Globe-Country-City-Hotel

When I rightClick on the Globe I want to add a country
I rightClick on the Country I want to add a City and so on

IT FAILS WHEN I REFER TO THE MAIN FORM ROOT NODE WHY?


I TESTED THE FOLLOWING AND WORK

A FORM 
A TREEVIEW 
A BUTTON
A TEXT BOX


CODE THAT WORKS!!!########
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles MyBase.Load
        Dim GlobeNode As TreeNode = New TreeNode()
        GlobeNode = tvw1.Nodes.Add("Globe")
    End Sub
 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles Button2.Click
        Dim GlobeNode As TreeNode
        GlobeNode = tvw1.Nodes(0)
        GlobeNode.Nodes.Add(txtAddModifyCountry.Text)
    End Sub
'////###################

THE FOLLOWING DOES NOT WORK!!!

A MAIN FORM WHERE THERE IS TREEVIEW
BUTTON THAT CALLS A FORM WITH A TEXT BOX AND OK BUTTON


'####   MAIN FORM  
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles MyBase.Load
        Dim GlobeNode As TreeNode = New TreeNode()
        GlobeNode = tvw1.Nodes.Add("Globe")
    End Sub

CLICK BUTTON ADD COUNTRY
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles Button1.Click
        Dim ofrmAddModifyCountry As frmAddModifyCountry = New 
frmAddModifyCountry()

        With ofrmAddModifyCountry
            .Text = "Add Modify Country"
        End Wit
End Sub

  Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles btnOk.Click
        '//Form where the treeview is
        Dim ofrm As Form1 = New Form1()

        Dim GlobeNode As TreeNode
        GlobeNode = ofrm.tvw1.Nodes(0)  'HERE IT FAILS WHY
        GlobeNode.Nodes.Add(txtAddModifyCountry.Text)

    End Sub



COULD YOU TELL ME WHY IT FAILS ???

tHANKS
Gabriel

  Return to Index