Winforms Question.

  • Thread starter Thread starter Manuel Canas
  • Start date Start date
M

Manuel Canas

Hi there,

I'm trying to trasfer some data from one form to another. I know I could use
global variables to trasfer the data from one form to another. I know is got
to be another way to do this not involving global variables.

Can anybody give some advices or hints or some ways that I can do this?

Thanks very much.

Manuel
 
Thanks Scott,

I thought about inheritance for sure, but as you said is not the prettiest.
My forms are totally different from each other. If I inherit from the first
form, all the controls from the first form will show up on my second form,
not good.

I need need the information from 5 or 6 text boxes to be transffered into my
second form. that's all I need.

Thanks,

Manuel
 
Manuel,

You can share data between forms a few different ways (probably more than
what I'll suggest). First you can use shared variables.

Form1:
Public Shared var1 as String
var1 = txtbox.Text

Form2:
Dim myvar as String
myvar = Form1.var1

Another way you can share data is to pass it to the form through a
constructor.
Form1
Dim form2instance as New Form2(txt1.Text, txt2.Text)
form2Instance.Show()

Form2:

Dim myval1 as String
Dim myval2 as String

Public Sub New(Byval var1, Byval var2)
Mybase.New()
InitializeComponent()
myval1 = var1
myval2 = var2
End Sub

Hope this helps

-Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top