473,324 Members | 2,193 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,324 software developers and data experts.

Passing info from one from to another

I have tried to pass information from one form to another
using the described method in the documentation, but
everytime I attempt to do this I get an error message that
states that I have a null reference. I am entering data
into a text box on one form and attempting to use that
data on a second form. The problem is that the data never
gets to the second form. Any ideas?
Nov 16 '05 #1
4 3918
Probably need more information about how the two forms are instantiated.
Are you passing/assigning a reference to form1 in form2?
If form1 has a text box, you could create a property to return
the value of the text box but form2 would need a reference to form1.
You could accomplish this when they are created:

MyFormClass form1 = new MyFormClass();
MyFormClass form2 = new MyFormClass();
form2.MyFormClassPointer = form1; //MyFormClassPointer is a public variable or property defined in the MyFormClass...
....or something like that....

Steve

"thawk" wrote:
I have tried to pass information from one form to another
using the described method in the documentation, but
everytime I attempt to do this I get an error message that
states that I have a null reference. I am entering data
into a text box on one form and attempting to use that
data on a second form. The problem is that the data never
gets to the second form. Any ideas?

Nov 16 '05 #2
Pass the form1 as a paramter in the constructor of Form2

Form1 myform1 = new Form1();

//pass form 1 as parameter in the constructor
Form2 myform2 = new Form2(myform1 );

--
Shak
(Houston)
"thawk" <an*******@discussions.microsoft.com> wrote in message
news:29*****************************@phx.gbl...
I have tried to pass information from one form to another
using the described method in the documentation, but
everytime I attempt to do this I get an error message that
states that I have a null reference. I am entering data
into a text box on one form and attempting to use that
data on a second form. The problem is that the data never
gets to the second form. Any ideas?

Nov 16 '05 #3
If Form1 creates Form2 then you can have a Form1 field in Form2:

public Form1 form1; // or create a property instead of a public field

Then when Form1 creates Form2, assign the public field a value. This code
is in Form1:

Form2 form2 = new Form2();
form2.form1 = this;

Now, the Form2 instance can pass values back to the Form1 instance.

Dale

"thawk" <an*******@discussions.microsoft.com> wrote in message
news:29*****************************@phx.gbl...
I have tried to pass information from one form to another
using the described method in the documentation, but
everytime I attempt to do this I get an error message that
states that I have a null reference. I am entering data
into a text box on one form and attempting to use that
data on a second form. The problem is that the data never
gets to the second form. Any ideas?

Nov 16 '05 #4
I took the information I used to pass between forms directly from the msdn library and it didn't appear to work.

private Form1 otherForm;
private void GetOtherTextBox()
{
textBox1.Texxt = otherForm.TextBox1.Text;
}

on form2

private TextBox TextBox1
{
get
{
textBox1.Text = TextBox1.Text;
}
}

something like this, I don't have the page in front of me, it is at work and I am now at home. This is where i get the null reference and can't figure out why...

"DalePres" wrote:
If Form1 creates Form2 then you can have a Form1 field in Form2:

public Form1 form1; // or create a property instead of a public field

Then when Form1 creates Form2, assign the public field a value. This code
is in Form1:

Form2 form2 = new Form2();
form2.form1 = this;

Now, the Form2 instance can pass values back to the Form1 instance.

Dale

"thawk" <an*******@discussions.microsoft.com> wrote in message
news:29*****************************@phx.gbl...
I have tried to pass information from one form to another
using the described method in the documentation, but
everytime I attempt to do this I get an error message that
states that I have a null reference. I am entering data
into a text box on one form and attempting to use that
data on a second form. The problem is that the data never
gets to the second form. Any ideas?


Nov 16 '05 #5

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

Similar topics

2
by: Richard | last post by:
**** Post for FREE via your newsreader at post.usenet.com **** HI, I am working on a project where I need to input data to a (local) HTML page using multiple form elements, such as text,...
6
by: Garma | last post by:
According to what I have learnt so far, instantiating global objects should be the last resort. Is there any reasons why so? Sometimes some objects or their pointers have to be shared among...
6
by: Catherine Jones | last post by:
Hi all, we need urgent help in a matter. We are trying to pass a COM object from the client to server and are facing some problems in the same. We've our client in C# as well as the Server...
8
by: Johnny | last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form (fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip code. The user can enter a zip code in the text box and...
1
by: Irfan Akram | last post by:
Hi People, Just wondering how we can pass info from one page to another when we enter Response.Redirect("CertainPage.aspx",false), so that we can observe this information and display...
2
by: lacombpcs | last post by:
I have a web app that searches a database and returns a datagrid table. the user inputs the search terms into a textbox. The user selects the info he wants and it sends him to a 2nd page, after...
1
by: Roy | last post by:
I'm assuming this is amazingly simple and I'm just missing the boat. On the html side of an asp.net page I have a datagrid, a "search" button, and 8 text boxes for search criteria. A user enters...
3
by: James Robertson | last post by:
I am new to the ASP and VB thing so be kind. Question I have is that I have created an ASPX web site to use as an E-Mail page. But I want to use this for a lot of users. Can I create the link on...
5
by: Markus Ernst | last post by:
Hello A class that composes the output of shop-related data gets some info from the main shop class. Now I wonder whether it is faster to store the info in the output class or get it from the...
3
by: Mufasa | last post by:
Are the only two real options for passing info between pages using QueryString and Session Variables? Am I missing any other viable way? TIA - Jeff.
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...
0
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...
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.