How to pass parameter between two forms?

  • Thread starter Thread starter Agnes
  • Start date Start date
A

Agnes

There is a button in form A , as the users click it, Form B will show.
however, how can i pass the parameter to form B .
the parameters got (tablesname,search condition).
As form B receive these condition. the listbox in form B will show the
result.

How can I do this ??
Thanks in advance
From Agnes Cheng
 
Hi,
There are many ways you can do it. Hee is one:

On the form A:

Private Sub btnOpenFormB_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles btnOpenForm2.Click
Dim f As New FormB
f.TextBox1.Text = Me.TextBox1.Text
f.TextBox2.Text = Me.TextBox2.Text
f.Show()
End Sub

Hugh
 
In addition, since you don't need to populate controls directly i would try
an other way.
(it's probably possible to send parameters in the new form statement but i
never tried that)
I usually set private vars in the target form and expose those using
properties.

something like:
\\
Public Class formB
Inherits System.Windows.Forms.Form
private strTableName as string
private strSearchCon as string
....
win form generated code
....
Public Property TableName() as string
Get
Return strTableName
End Get
Set(ByVal Value As String)
strTableName = Value
End Set
End Property

Public Property SearchCon () as string
Get
Return strSearchCon
End Get
Set(ByVal Value As String)
strSearchCon = Value
End Set
End Property
//

then you can go on w Hugh's suggestion
Private Sub btnOpenFormB_Click(ByVal sender As Object,
ByVal e As System.EventArgs) Handles btnOpenForm2.Click
Dim f As New FormB
f.TableName= Me.TextBox1.Text
f.SearchCon = Me.TextBox2.Text
f.Show()
End Sub

the vars in form B are now populated.

Hope it helps

eric
 
Back
Top