473,796 Members | 2,595 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "DisabledCo unt" how can i show them on my 2nd form?

Many Thanks,

Ash

Oct 30 '07 #1
8 2557
On Oct 31, 3:05 am, AshP...@gmail.c om 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 "DisabledCo unt" 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.showdialo g;
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.DisabledC ount = disabledCount;
this.Visible = false;
form2.showdialo g;
this.Visible = trrue;

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

Oct 30 '07 #2
On Oct 30, 10:28 pm, maxxx <mailma...@gmai l.comwrote:
On Oct 31, 3:05 am, AshP...@gmail.c om 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 "DisabledCo unt" 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.showdialo g;
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.DisabledC ount = disabledCount;
this.Visible = false;
form2.showdialo g;
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.DisabledC ount = disabledCount;

i have done that and i get an error:

"form2.CarC ount 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.CarC ount 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...@g mail.comwrote:
"form2.CarC ount 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.c om wrote:
On Nov 1, 9:28 am, Marc Gravell <marc.grav...@g mail.comwrote:
"form2.CarC ount 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.c om 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 "DisabledCo unt" 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
2456
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 following are page1.html and page2.html that use Array JavaScript object to pass data back and forth. page1.html is able to transfer data to page2.html, but page2.html has trouble to transfer data back to page1.html.
7
23657
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 the server since it's GET or POST request. But if just form-to-form communication, why we need to send the form to the server? Please help clarify. Thanks!! <form action="process.asp" method="get"> //form controls <input type="submit">
4
5394
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 product the visitor can order by clicking one or more checkboxes. I made a form containing input with type "checkbox" like: <form> <input type="checkbox" name=ck id=ck
8
3370
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
5353
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 appreciate. Thank you. Juky
4
5751
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 know, I have to manually enter 3 numbers into 3 fields of a form on that webpage. Is there a way I could pass the info in the url so that when the page loads it will have the form already filled in with my data? I have figured out how to do this...
14
3608
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 click a button to bring up FormB which needs to display values entered in FormA. Thanks in advance.
24
55238
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 EventHandler(Onbutton_click); I want to pass more information related that event. & want to use that
12
11115
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. Here is a newbie mistake that I found myself doing (as a newbie), and that even a master programmer, the guru of this forum, Jon Skeet, missed! (He knows this I'm sure, but just didn't think this was my problem; LOL, I am needling him) If...
9
2558
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 this line: $result = $_POST; I need the $result on the clm_historyXL page to print a list to excel because of a header already being sent.
0
9679
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9527
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10223
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10172
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9050
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.