473,399 Members | 3,656 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Accessing controls in another form

Hi

Using VB.net 2003

I know how to access controls on a 2nd form after declaring the form in
the first.

But how do I access the controls on the original form from the 2nd form.

(in frmMain)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim form2 As New Form2
form2.TextBox1.Text = TextBox1.Text
form2.Show()
End Sub

(in Form2)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim form1 As New Form1
form1.TextBox1.Text = TextBox1.Text
form1.Update()
Me.Close()

End Sub
Form2 textbox updates ok
The textbox in form1 does not update and still holds the original text
before opening Form2

This is just a simple example I cannot get working, once I can get this
working the I should not have problems with the actual code I need to use.

There must be a simple answer to this....???

Thanks in advance for any help given

DaveG

Jul 21 '05 #1
3 1381
Hi Dave,

You need to pass a reference to your 1st form when declaring the 2nd, typically

Form2 f2 = new Form2(this); // Me in VB

Overload the constructor of the 2nd form to accept a 1st form parameter.
Store the parameter for later use

On Sat, 30 Apr 2005 13:29:05 +0200, DaveG <no**********@daveg.co.uk> wrote:
Hi

Using VB.net 2003

I know how to access controls on a 2nd form after declaring the form in
the first.

But how do I access the controls on the original form from the 2nd form.

(in frmMain)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim form2 As New Form2
form2.TextBox1.Text = TextBox1.Text
form2.Show()
End Sub

(in Form2)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim form1 As New Form1
form1.TextBox1.Text = TextBox1.Text
form1.Update()
Me.Close()

End Sub
Form2 textbox updates ok
The textbox in form1 does not update and still holds the original text
before opening Form2

This is just a simple example I cannot get working, once I can get this
working the I should not have problems with the actual code I need to use.

There must be a simple answer to this....???

Thanks in advance for any help given

DaveG


--
Happy coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #2
Thanks Morten

Noe the problem is I have used the overload in normal funtions and subs
but never with the constructors, so now I'm a little lost, I understand
the reasons for the overload..... so the New form2(Me) will be excepted
bur how to implement it is where I am stuck......

On Sat, 30 Apr 2005 13:56:50 +0200, Morten Wennevik wrote:
Hi Dave,

You need to pass a reference to your 1st form when declaring the 2nd, typically

Form2 f2 = new Form2(this); // Me in VB

Overload the constructor of the 2nd form to accept a 1st form parameter.
Store the parameter for later use

On Sat, 30 Apr 2005 13:29:05 +0200, DaveG <no**********@daveg.co.uk> wrote:
Hi

Using VB.net 2003

I know how to access controls on a 2nd form after declaring the form in
the first.

But how do I access the controls on the original form from the 2nd form.

(in frmMain)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim form2 As New Form2
form2.TextBox1.Text = TextBox1.Text
form2.Show()
End Sub

(in Form2)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim form1 As New Form1
form1.TextBox1.Text = TextBox1.Text
form1.Update()
Me.Close()

End Sub
Form2 textbox updates ok
The textbox in form1 does not update and still holds the original text
before opening Form2

This is just a simple example I cannot get working, once I can get this
working the I should not have problems with the actual code I need to use.

There must be a simple answer to this....???

Thanks in advance for any help given

DaveG


Jul 21 '05 #3
Dave, overloading a constructor is done the exact same way, although I'm not sure how the VB syntax is. Store the Form1 reference for later use.

private Form1 myParent;

public Form2(Form1 f)
{
myParent = f;
}

then simply call

myParent.MethodOrSimilarInForm1()

whenever you need.
On Sat, 30 Apr 2005 21:51:15 +0200, DaveG <no**********@daveg.co.uk> wrote:
Thanks Morten

Noe the problem is I have used the overload in normal funtions and subs
but never with the constructors, so now I'm a little lost, I understand
the reasons for the overload..... so the New form2(Me) will be excepted
bur how to implement it is where I am stuck......

On Sat, 30 Apr 2005 13:56:50 +0200, Morten Wennevik wrote:
Hi Dave,

You need to pass a reference to your 1st form when declaring the 2nd, typically

Form2 f2 = new Form2(this); // Me in VB

Overload the constructor of the 2nd form to accept a 1st form parameter.
Store the parameter for later use

On Sat, 30 Apr 2005 13:29:05 +0200, DaveG <no**********@daveg.co.uk> wrote:
Hi

Using VB.net 2003

I know how to access controls on a 2nd form after declaring the form in
the first.

But how do I access the controls on the original form from the 2nd form.

(in frmMain)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim form2 As New Form2
form2.TextBox1.Text = TextBox1.Text
form2.Show()
End Sub

(in Form2)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim form1 As New Form1
form1.TextBox1.Text = TextBox1.Text
form1.Update()
Me.Close()

End Sub
Form2 textbox updates ok
The textbox in form1 does not update and still holds the original text
before opening Form2

This is just a simple example I cannot get working, once I can get this
working the I should not have problems with the actual code I need to use.

There must be a simple answer to this....???

Thanks in advance for any help given

DaveG



--
Happy coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tom Meuzelaar | last post by:
Hello: I'm using VB6 in VS enterprise. I'd like to place an HTML form inside a VB container, have a user fill out the form information, click a submit button, and then have the program capture...
4
by: Jim Heavey | last post by:
Hello, I have created a form which I intend to use a a dialog box. It has a few controls on that form and I changed the properties of those controls to "public" with the idea that I could access...
4
by: Andrew Diabo | last post by:
I have 2 forms (Form1 and Form2) in my C# project. I created the second form from the main form like so: Fom2 aForm = new Form2(); aForm.ShowDialog(); How do I access the properties of a...
3
by: Tim Fitzgerald | last post by:
Hello all, I have no problem accessing another form in my app.. however, when I try to access a ListView on a different form, I come up empty... Basically, Dim pForm As New frmMain Dim iCount...
0
by: Geraldine Hobley | last post by:
Hello I have a problem whereby I have a treeview control on one form called projecttree and I wish to clea the nodes from this control in another form The form that contains the treeview is...
5
by: RSH | last post by:
I havent been able to set a property from another class with out getting some sort of error. Can someone please tell me what I'm doing wrong here? Public Class Form1
4
by: raj_genius | last post by:
I hav two queries, whc are as follows: FIRSTLY: is it possible to access the controls(by name) of a parent form(MDI) from its child forms??if yes then how??plzz provide a coded example in VB if...
8
by: colmkav | last post by:
Hi, could someone tell me how I can check whether a database is open by name eg something like db("mydbname")
3
by: M K | last post by:
I have 2 classes. One where the form resides and I created another one for all the database stuff. after i get data from the db i want to be able to update the form. I have the namespace of...
2
by: San24 | last post by:
Guys, Let me explain the application I have - Form > Main Tab Control > Main Tab Page > User Control > Sub Tab Control > Sub Tab Page > User Control > Contols/Text Box. Form - The main...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.