How to pass form data to another form?

seahck

Member
Joined
Jul 12, 2004
Messages
6
Programming Experience
Beginner
How to pass form data to another form?
i have 2 form, form1 and form2 and how can i pass a value that i select in data grid on form1 to a textbox on form2?
 

mzim

Well-known member
Joined
Jun 3, 2004
Messages
187
Location
Other side of the rock
Programming Experience
1-3
try this one:
VB.NET:
  'in your form1 instantiate the form2
  dim d as new form2
  'in the datagrid click events
  d.TextBox1.Text = DataGrid1.Item(DataGrid1.CurrentCell.RowNumber, DataGrid1.CurrentCell.ColumnNumber)
hope this helps..
 

rhinton

Member
Joined
Nov 30, 2004
Messages
5
Programming Experience
1-3
add a module to your project and declare public variables in it. Those variable will be accessible throughout the project.
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
rhinton said:
add a module to your project and declare public variables in it. Those variable will be accessible throughout the project.
declare application wide variables as Friend, not Public public shares yer variable system wide (can be accessed by completely seperate programs) whereas Friend keeps it to your app only

use friend instead of public
 

rex028

Well-known member
Joined
Nov 18, 2004
Messages
50
Programming Experience
Beginner
i still dun know how to do it ..

may be i should make my question more clearly ...

i have
Form1 , Form2
Dg1, Dg2


now .. i add a new Purchase Order in Form1 ..
Dg1 show a new Purchase order with Blank Record...

Then

i search the Item in Form2
Dg2 show all items ...

then

i select a Row(an item)in Dg2 then press Add or Double click it

then

Selected item will pass to Dg1

Finally

i pass Confirm to save the Purchase Order

could you guys teach me how to achieve stuff above ...
please help ... i need this function so much .. !!
 

NYCSavage

New member
Joined
Dec 15, 2004
Messages
1
Programming Experience
Beginner
a simple way to do so is to declare this at the top:

public shared username as string


then in the open new form code:

user = txtUser.Text
Try

Dim currentform = New frmAccess

currentform.Show()

Catch ex As Exception

MessageBox.Show(ex.Message())

End Try



then on the new form load code:

lblUser.Text = ("User: " & frmLogin.user)
 
Top Bottom