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

sharing data between forms / passing data from one to another

hello,

i'm a begginer in c# and even though i searched google and used two books for begginers i'm just not able to solve this problem. please help me on this:

so i have two forms form1 and form2

lets say that in form1 is textboxA and button that opens form2, so when i click on the button i open form2 and i want from textboxB in form2 pass data to form1 textboxA (for example when i click on ok button in form2 and close it). How can i do that?

how can i access form1 textboxA from form2? is it even possible? should i do it some other way?

thank you for any help

ps: for example is to possible to do some textbox "public" so i can access that from any form?
Nov 1 '09 #1

✓ answered by fastestindian

Check out the following code.
Expand|Select|Wrap|Line Numbers
  1.  // This method demonstrates a pattern for making thread-safe
  2.         // calls on a Windows Forms control. 
  3.         //
  4.         // If the calling thread is different from the thread that
  5.         // created the TextBox control, this method creates a
  6.         // SetTextCallback and calls itself asynchronously using the
  7.         // Invoke method.
  8.         //
  9.         // If the calling thread is the same as the thread that created
  10.         // the TextBox control, the Text property is set directly. 
  11.  
  12.         private void SetText(string text)
  13.         {
  14.             // InvokeRequired required compares the thread ID of the
  15.             // calling thread to the thread ID of the creating thread.
  16.             // If these threads are different, it returns true.
  17.             if (this.textBox1.InvokeRequired)
  18.             {    
  19.                 SetTextCallback d = new SetTextCallback(SetText);
  20.                 this.Invoke(d, new object[] { text });
  21.             }
  22.             else
  23.             {
  24.                 this.textBox1.Text = text;
  25.             }
  26.         }
For link to to
http://msdn.microsoft.com/en-us/libr...28(VS.80).aspx

1 2292
Check out the following code.
Expand|Select|Wrap|Line Numbers
  1.  // This method demonstrates a pattern for making thread-safe
  2.         // calls on a Windows Forms control. 
  3.         //
  4.         // If the calling thread is different from the thread that
  5.         // created the TextBox control, this method creates a
  6.         // SetTextCallback and calls itself asynchronously using the
  7.         // Invoke method.
  8.         //
  9.         // If the calling thread is the same as the thread that created
  10.         // the TextBox control, the Text property is set directly. 
  11.  
  12.         private void SetText(string text)
  13.         {
  14.             // InvokeRequired required compares the thread ID of the
  15.             // calling thread to the thread ID of the creating thread.
  16.             // If these threads are different, it returns true.
  17.             if (this.textBox1.InvokeRequired)
  18.             {    
  19.                 SetTextCallback d = new SetTextCallback(SetText);
  20.                 this.Invoke(d, new object[] { text });
  21.             }
  22.             else
  23.             {
  24.                 this.textBox1.Text = text;
  25.             }
  26.         }
For link to to
http://msdn.microsoft.com/en-us/libr...28(VS.80).aspx
Nov 2 '09 #2

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

Similar topics

4
by: Ryann | last post by:
Hello. I am creating a form that has 5 steps/pages. Each page contains about 20 fields. But I don't want to write them until they submit on the last page. I figured out that I can use hidden...
10
by: Noozer | last post by:
Below is some ASP, HTML and javascript. It is part of a page used to maintain a small database. This code did work at one time, but has since stopped. For some reason the data on my form is not...
42
by: Dan | last post by:
Hello, I have trouble with class calling. I am calling getvolume() with succes in the function CreateCircle but it do not want to call it in ShowCircle() function. I am staying in the same...
21
by: MLH | last post by:
A97 procedure to open http://www.arch.com/message/ enter an 800 number, press "Continue", enter a text msg string from a memo field and press "Send" This is a calendaring and appointment A97...
5
by: Rod | last post by:
I've written 2 ASP.NET applications (I've worked on one with a team and another by myself). In my ASP.NET pages, when saving data to a backend database I've done it by using the click event of a...
15
by: http://www.visual-basic-data-mining.net/forum | last post by:
Does anyone have any idea how to transferring data from TextBox1 in form1 to textBox2 in form2..... That means after i fill in any data in textBox1 and click Next button... It will bring me to...
4
by: radiax | last post by:
Iam trying to find a simple solution for sharing data between windows applications( apart of using file system or remoting or MMF) . I tried using class library by making data members "shared" but...
9
by: kirk | last post by:
I have program.cs, my "main" form and then a "settings" form. My "main" form existed for awhile and I had constants, instantiations, properties, etc within it created. I went to create my...
45
by: =?Utf-8?B?QmV0aA==?= | last post by:
Hello. I'm trying to find another way to share an instance of an object with other classes. I started by passing the instance to the other class's constructor, like this: Friend Class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
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,...

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.