473,409 Members | 1,966 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,409 software developers and data experts.

How do i pass data from form 1 to form 2

Hi all,

I have 2 forms, "Form1" & "Form2", i have a button that currently
opens form2 from form1 and then hides itself:

Form2 form2 = new Form2();
form2.show;
this.Visible = False;

and then the same on form2 to get back to my 1st form:

Form1 form1 = new Form1();
form1.show;
this.Visible = False;
Ok, now i have 3 values on form 1 and they are "carCount", "bikeCount"
and "DisabledCount" how can i show them on my 2nd form?

Many Thanks,

Ash

Oct 30 '07 #1
8 2546
On Oct 31, 3:05 am, AshP...@gmail.com wrote:
Hi all,

I have 2 forms, "Form1" & "Form2", i have a button that currently
opens form2 from form1 and then hides itself:

Form2 form2 = new Form2();
form2.show;
this.Visible = False;

and then the same on form2 to get back to my 1st form:

Form1 form1 = new Form1();
form1.show;
this.Visible = False;

Ok, now i have 3 values on form 1 and they are "carCount", "bikeCount"
and "DisabledCount" how can i show them on my 2nd form?

Many Thanks,

Ash
1st thing - you don't want to create a new Form1 when you click the
button on Form2 do you? Don't you really want to make Form1 visible
again?
If Form1 is going to be invisible, you could show form 2 modally..
e.g.
Form2 form2 = new Fomr2();
this.Visible = false;
form2.showdialog;
this.Visible = trrue;

then in the click event of Form2, simply close the form.

As for passing data, the simplest way is to have public properties in
the Form2 of CarCount, BikeCOunt and DisabledCount.
then extend the code in Form1 to have...
Form2 form2 = new Fomr2();
form2.CarCount = carcount;
form2.BikeCOunt = bikeCount;
form2.DisabledCount = disabledCount;
this.Visible = false;
form2.showdialog;
this.Visible = trrue;

Or somethng like that...
Cheers
..\\axxx

Oct 30 '07 #2
On Oct 30, 10:28 pm, maxxx <mailma...@gmail.comwrote:
On Oct 31, 3:05 am, AshP...@gmail.com wrote:


Hi all,
I have 2 forms, "Form1" & "Form2", i have a button that currently
opens form2 from form1 and then hides itself:
Form2 form2 = new Form2();
form2.show;
this.Visible = False;
and then the same on form2 to get back to my 1st form:
Form1 form1 = new Form1();
form1.show;
this.Visible = False;
Ok, now i have 3 values on form 1 and they are "carCount", "bikeCount"
and "DisabledCount" how can i show them on my 2nd form?
Many Thanks,
Ash

1st thing - you don't want to create a new Form1 when you click the
button on Form2 do you? Don't you really want to make Form1 visible
again?
If Form1 is going to be invisible, you could show form 2 modally..
e.g.
Form2 form2 = new Fomr2();
this.Visible = false;
form2.showdialog;
this.Visible = trrue;

then in the click event of Form2, simply close the form.

As for passing data, the simplest way is to have public properties in
the Form2 of CarCount, BikeCOunt and DisabledCount.
then extend the code in Form1 to have...
Form2 form2 = new Fomr2();
form2.CarCount = carcount;
form2.BikeCOunt = bikeCount;
form2.DisabledCount = disabledCount;
this.Visible = false;
form2.showdialog;
this.Visible = trrue;

Or somethng like that...
Cheers
.\\axxx- Hide quoted text -

- Show quoted text -
Thankyou for your response, i will give that a shot and see how it
goes. the only reason i make form 1 invisible is so then i just set it
as visible when i close my 2nd form

Many thanks,

Ash

Nov 1 '07 #3
form2.CarCount = carcount;
form2.BikeCount = bikeCount;
form2.DisabledCount = disabledCount;

i have done that and i get an error:

"form2.CarCount inaccessible due to protection level" i think and its
the same for the other 2. Any ideas?

Many thanks,
Ash
Nov 1 '07 #4
"form2.CarCount inaccessible due to protection level"
Well, are they public properties as was suggested? i.e.

class Form2 : Form {
...
private int carCount;
public int CarCount {
get {return carCount; }
set {carCount = value;}
}
...
}

Nov 1 '07 #5
On Nov 1, 9:28 am, Marc Gravell <marc.grav...@gmail.comwrote:
"form2.CarCount inaccessible due to protection level"

Well, are they public properties as was suggested? i.e.

class Form2 : Form {
...
private int carCount;
public int CarCount {
get {return carCount; }
set {carCount = value;}
}
...
=====================================

ok sorry about this, im struggleing a little:

so far i have this in form 2 like you said:

class Form2 : Form
{
private int carCount;
public int CarCount
{
get {return carCount; }
set {carCount = value;}
}
but i get a message saying that Form2.Form2 allready has carCount
defined

Nov 1 '07 #6
On Nov 2, 12:22 am, AshP...@gmail.com wrote:
On Nov 1, 9:28 am, Marc Gravell <marc.grav...@gmail.comwrote:
"form2.CarCount inaccessible due to protection level"
Well, are they public properties as was suggested? i.e.
class Form2 : Form {
...
private int carCount;
public int CarCount {
get {return carCount; }
set {carCount = value;}
}
...

=====================================

ok sorry about this, im struggleing a little:

so far i have this in form 2 like you said:

class Form2 : Form
{
private int carCount;
public int CarCount
{
get {return carCount; }
set {carCount = value;}

}

but i get a message saying that Form2.Form2 allready has carCount
defined
I would check your capitalisation. Personally I tend to prefix my
private variables with an underscore...
So
private int _carCount;
public int CarCount
{
....etc
}
if the compiler says it already has carCopunt defined then you can bet
it has - so just look through checking you have capitalised correctly.

Cheers

Nov 6 '07 #7
Hey have a Look for Model-View-Controller(MVC) patterns on google. It
will definitely cater for information being sent from one form to
another , might be over kill in this case

Niq

On Oct 30, 7:05 pm, AshP...@gmail.com wrote:
Hi all,

I have 2 forms, "Form1" & "Form2", i have a button that currently
opens form2 from form1 and then hides itself:

Form2 form2 = new Form2();
form2.show;
this.Visible = False;

and then the same on form2 to get back to my 1st form:

Form1 form1 = new Form1();
form1.show;
this.Visible = False;

Ok, now i have 3 values on form 1 and they are "carCount", "bikeCount"
and "DisabledCount" how can i show them on my 2nd form?

Many Thanks,

Ash

Nov 6 '07 #8
thankyou all for your responses and help, i have managed to do that

thankyou all

Many thanks,

Ash

Nov 9 '07 #9

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

Similar topics

0
by: Matt | last post by:
My problem is to allow ASP to interact with JSP, and I pass JavaScript object in my approach, but I wonder if it will work in network, not just in local machine. For testing purposes, the...
7
by: Matt | last post by:
In ASP, when we pass data between pages, we usually pass by query string. If we pass data by query string, that means we need to use submit button, not by regular button, and the form will pass to...
4
by: Fred | last post by:
Hi, i know how to pass a value from Javascript to ASP with a hidden field into a form and submitting it, or with cookies, but here i have to pass a lot of data in an array. There is a list of...
8
by: Brian F | last post by:
Exactly what the subject says. I have an ASP page that I want my C# windows application to open in Internet Explorer, and if possible have it send along a list of values from a list box. Thank you.
6
by: juky | last post by:
Hi all, I have 2 applications one in VB.net and the other in VC6. I need to pass data between them. How can I do it? what's the best way to implement such communication ? Any comment will be...
4
by: ryang | last post by:
I'm sure this is an easy one for you old pros? I am using filemaker to browse some records, and I have created a button in my filemaker layout that launches a web browser with a certain url. Right...
14
by: =?Utf-8?B?Umljaw==?= | last post by:
I have seen examples of passing data from FormB to FormA (Parent To Child) but I need an example of passind data from FormA to FormB. My main form is FormA; I will enter some data in textboxes and...
24
by: =?Utf-8?B?U3dhcHB5?= | last post by:
Can anyone suggest me to pass more parameters other than two parameter for events like the following? Event: Onbutton_click(object sender, EventArgs e)" Event handler: button.Click += new...
12
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
9
by: JRough | last post by:
I tried to pass the $result from a mysql_query in a url like this line Header("Location:clm_historyXL.php?_result=".$result); but on the redirect location clm_history.php page I get an error on...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.