Problem passing parameters between parent and child forms

dav37

New member
Joined
Oct 19, 2007
Messages
1
Location
Texas
Programming Experience
Beginner
Hi I am very new to vb.net and I have a pretty strange question to ask. I am trying to pass a value from a treeview control to a new form. Basically I have a parent form that has a treeview control on it and when the user selects the node I want to pass the selected node to the child form so I can populate a dataset. I finally figured out how to pass parameters to forms by overloading? the constructor of the form to accept a parameter. The problem is that I can't seem to pass the node I can only pass a parm that is loaded by a "literal"

for example:
selectnode = "Dave" vs. selectnode = e.node.text

Here is my code for the forms thanks in advance for your help

For Form1:

Public Shared Selectnode As String
Public Shared otherForm As New Form2(Selectnode)

Public Sub TreeView1_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles

TreeView1.AfterSelect
Dim pnode = "Client"
Dim Selectnode = e.Node.Text
If e.Node.Text <> pnode Then
CLIENTABLE2TableAdapter.Fill(Me.AHSCLIENT2DataSet. CLIENTABLE2, Selectnode)
otherform.show()
End If
End Sub

For Form2:

Public Class Form2
Inherits System.Windows.Forms.Form

' Windows Forms Designer generated code region

Public param As String

Public Sub New(ByVal newparameter As String)
MyBase.New()
InitializeComponent()
param = newparameter
End Sub


Public Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(param)
End Sub
End Class
 
Back
Top