Cant solve this easy problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Folks

I am starting to learn VB.NET. A problem that i have encountered is that i cannot seem to use the values in my textbox accross forms

for example i have 2 forms. On form2 i have a search facility that allows the user to search for the guests in a hotel. When the user has selected a guest from the datagrid the chosen guest details are placed in numerous textboxes using the databinding)
What i want to do now is when the guest clicks the Exit button, i want the text that is in the textboxes in form2 to appear in the textboxes in form1

Is there anyway i can do this?

In VB6 i could just use the form name to do this. i.
Form1.textbox1.text = Form2.textbox2.text
 
Set public properties in the second form, Value1 and Value2 for instance.
Then, make sure you set them before form2 closes. You'll be able to
reference them from the same code block that you called Show() or
ShowDialog() from
Varun said:
Hi Folks,

I am starting to learn VB.NET. A problem that i have encountered is that i
cannot seem to use the values in my textbox accross forms.
for example i have 2 forms. On form2 i have a search facility that allows
the user to search for the guests in a hotel. When the user has selected a
guest from the datagrid the chosen guest details are placed in numerous
textboxes using the databinding).
What i want to do now is when the guest clicks the Exit button, i want the
text that is in the textboxes in form2 to appear in the textboxes in form1.
 
Hi William

How would i create a public property

Public Value2 as string ???

Also i confuse by what you say when talking about referencing these values.
Are you saying i can use these varibles to fill the textboxes on form1 before i display it

i.e when i use the Form2.close on the exit buttons onclick event?

many thx
 
Public Property Whatever as WhateverType
Get
Return WhateverPrivateVariable
Set
WhateverPrivateVariable = Value
End Property

Then in the first form

Dim f as New SecondForm
f.ShowDialog

Dim s as WhateverType = f.Whatever
 
You can have a data propogation logic instead of making variables public or keeping the form instance in the memory to get the data from that.

Overload the form class constructors for data passage, you can pass the data via resepective objects or you can stuff all the required objects in a hashtable and pass that hashtable to second form via overloaded constructor.
 
Hi Varun

Adding to the advise that you have been given.

Take a look at this article. It shows you one way of accessing Controls
across Forms in .NET

http://www.devcity.net/net/article.aspx?alias=multipleforms2

Hope this helps with your problem.

Neil Knobbe
Visual Basic MVP
Varun said:
Hi Folks,

I am starting to learn VB.NET. A problem that i have encountered is that i
cannot seem to use the values in my textbox accross forms.
for example i have 2 forms. On form2 i have a search facility that allows
the user to search for the guests in a hotel. When the user has selected a
guest from the datagrid the chosen guest details are placed in numerous
textboxes using the databinding).
What i want to do now is when the guest clicks the Exit button, i want the
text that is in the textboxes in form2 to appear in the textboxes in form1.
 
Back
Top