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

How to pass values from 1 form to another in c# windows?

How to pass values from 1 form to another in c# windows?
Jul 9 '10 #1
2 1260
Sfreak
64
There are many ways to do that. Here are some examples:

You can declare a public static method on the first form that sets a static class attribute and call the method from the second form. Something like this:

##### Form that receive values

Expand|Select|Wrap|Line Numbers
  1. public partial class Form2 : Form
  2.     {
  3.         static string name { get; set; }
  4.         public Form2()
  5.         {
  6.             InitializeComponent();
  7.         }
  8.         public static void setName(string pName)
  9.         {
  10.             name = pName;
  11.         }
  12.     }
  13. ##### Form that send values
  14.  
  15.     public partial class Form1 : Form
  16.     {
  17.         public Form1()
  18.         {
  19.             InitializeComponent();
  20.         }
  21.  
  22.         private void button1_Click(object sender, EventArgs e)
  23.         {
  24.             Form2.setName("Sfreak");
  25.         }
  26.     }
Or you pass the instance of the form that will receive the values to the one that will send values to control it using methods with referenced parameters.

Better than this you can implement an Observer pattern that manages the first form using an Interface between them.
Jul 26 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Matthew Lasar | last post by:
I am trying to study php from a book. But the code doesn't seem to work for me. I set up a form, as follows: <html> <head> <title>form</title> </head> <body> <form action="results.php"...
2
by: Ben | last post by:
Hi, When clicking on a button, a new record must be created in an Access table. See my code: <% set objdc = Server.CreateObject("ADODB.Connection")...
2
by: Chandru | last post by:
hi I want to know how to pass values from different forms. That is, i created one parent form. from there i opened child form modeless way. Once i close the child form i need some value from...
2
by: Chane | last post by:
hi i have doubt in how to pass values back to the called form. I have two forms, each having a textbox and a button control. First i'm run the first form and click the button, it creates object...
2
by: Martin Tully | last post by:
I am trying to a create a page that will query a SQLDB get customer information and then pass this information on to another page creating almost like a mail merge letter. I can get the information...
3
by: Martin | last post by:
I have a calendar form that sends the inputted date back to a text box . Using the GET method, I would like to pass the date as a variable to another asp page. How do I do this? Thanks.
3
by: drec | last post by:
I am creating a search box that the user types a value in, and then this gets passed to another page called search.php I would like to be able to pass these values through the URL, but I cant...
7
by: Boki | last post by:
Hi All, I can't pass data to another form: in form2: private void button1_Click(object sender, EventArgs e) { Form1 form_copy = new Form1();
1
by: gopim | last post by:
in my registration page having around 20 fields,it is very difficult for users. i want to devide this registratino for into two sections.but my doubt is how can we store first section values with...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.