473,466 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Parameter Passing between windows forms, C#

I have two forms. From form one I have a listbox that when double
clicked I get the selected value (string) and store in a variable. I
parse the string to get the first 12 characters and store it in a
variable to query a sql db. I set break points to see the data as it
is passed from form1 and when calling the function from form2 to get
the variable, its contents are blank.

I believe what I'm looking for is some method to access an instance a
specific instance and not create a new one that seems to wipe
everything out.
Nov 15 '05 #1
2 17955
If I understand you correctly, form2 is used to display
the results of a db query whose parameter is selected
from form1. The query logic is in form2 and you can't
pass the variable. Is this correct?

If so, why don't you just pass the variable from form1 to
form2's function before displaying form2 instead of
trying to retrieve the variable from form1?

Form2 f2 = new Form2();
f2.GetSomeData(variableInQuestion);
f2.ShowDialog();

If that doesn't suit your needs, you could add a Caller
property to form2 and set it as 'this' before showing the
form.

Form2 f2 = new Form2();
f2.Caller = this;
f2.ShowDialog();

Then, in form2...

this.GetSomeData(Caller.variableInQuestion);
Most likely, though, I have misinterpreted your question
and was of no help whatsoever.

Charlie
-----Original Message-----
I have two forms. From form one I have a listbox that when doubleclicked I get the selected value (string) and store in a variable. Iparse the string to get the first 12 characters and store it in avariable to query a sql db. I set break points to see the data as itis passed from form1 and when calling the function from form2 to getthe variable, its contents are blank.

I believe what I'm looking for is some method to access an instance aspecific instance and not create a new one that seems to wipeeverything out.
.

Nov 15 '05 #2
"Charlie Williams" <cw***********@hotmail.com> wrote in message news:<00****************************@phx.gbl>...
If I understand you correctly, form2 is used to display
the results of a db query whose parameter is selected
from form1. The query logic is in form2 and you can't
pass the variable. Is this correct?

If so, why don't you just pass the variable from form1 to
form2's function before displaying form2 instead of
trying to retrieve the variable from form1?

Form2 f2 = new Form2();
f2.GetSomeData(variableInQuestion);
f2.ShowDialog();

If that doesn't suit your needs, you could add a Caller
property to form2 and set it as 'this' before showing the
form.

Form2 f2 = new Form2();
f2.Caller = this;
f2.ShowDialog();

Then, in form2...

this.GetSomeData(Caller.variableInQuestion);
Most likely, though, I have misinterpreted your question
and was of no help whatsoever.

Charlie
-----Original Message-----
I have two forms. From form one I have a listbox that

when double
clicked I get the selected value (string) and store in a

variable. I
parse the string to get the first 12 characters and

store it in a
variable to query a sql db. I set break points to see

the data as it
is passed from form1 and when calling the function from

form2 to get
the variable, its contents are blank.

I believe what I'm looking for is some method to access

an instance a
specific instance and not create a new one that seems to

wipe
everything out.
.


Charlie,

The first solution worked. I didn't know that I could accomplish it
that way. I was investigating the use of delegates to resolve this.

Thank you again

Chris
Nov 15 '05 #3

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

Similar topics

0
by: Tim Haughton | last post by:
I've just released an article on using Test Driven Development with C# and Windows Forms. GUI's are often difficult to test, so I thought it might be of interest. The article along with the...
6
by: billr | last post by:
I have developed a small API for taking care of a lot of boiler plate stuff in a multi formed windows application, for example setting up a messaging thread framework. New Forms, in the...
2
by: Alper AKCAYOZ | last post by:
Hello, I am developing a project using Windows Forms .NET by using Visual C++ .NET v2003. I open a Sub_Form by clicking a button on the Main_Form. Some operations are working at Main_Form and...
3
by: Chris Dunaway | last post by:
A quick scan of the group did not immediately reveal an answer to my questions so here goes. First let me describe my app and then I'll ask the questions. I am writing a Windows Forms App (not...
2
by: John Granade | last post by:
I'm looking for the best way to make a dataset available from multiple Windows forms. The dataset is created from an XML file. I have a main form (frmMain) that loads the dataset and reads the...
0
by: Filippo Bettinaglio | last post by:
VS2005, C# I have developed a UserControl embedded in a HTML web page. And I can access to the DOM with the following code: HTML page: …….. <BODY onload=loadDoc()> …….
2
by: Hakan Örnek | last post by:
Hi , I want to parameter passing to my windows sevice. I call service commands like this ; '------------------------------------------------------------ Dim sc As ServiceController sc = New...
4
by: Mo | last post by:
Hi, I am writing a console application to send a key sequence to an old clunky application on a regular interval using the windows scheduler. I can get it to work if it is a windows form...
4
by: Jerad Rose | last post by:
I'm baffled by this -- is there not a typed object used for ComboBox Items? Best I can tell, all of the methods for ComboBox that accept an Item are of type Object. Why in the world is a...
0
by: Pantokrator | last post by:
Hi! Could you please tell me what am I doing wrong here.... I've got a simple form called Form1 and all I want to do is to pass the pointer to my other class called CCueMakerEngine. Here's what...
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
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...
1
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
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,...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.