473,320 Members | 2,004 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.

Beginner: Referencing a control on another form

I have two forms, Form1 and Form2. From Form2, how do I reference the value
in a control on Form1?

Or perhaps a more specific question: Form1 contains a textbox with the value
of 10. This form is hidden. Form2 is active and a user enters a value of 2
into a blank text box. How can I add this value to the textbox in Form1 so
that when Form1 is displayed it's textbox displays 12?

I probably have the wrong mindset here; I'm thinking Access where I could
set a reference to a control on another form. Is this the way it's done in
..NET? Or do I need to save everything to variables and refresh each form
when it is activiated?
Nov 16 '05 #1
7 6158
Dave,
A cleaner design will be to create another class which manages your data.
Something based on the MVC pattern. You can find more information on this in
the User Interface Process Application Block on MSDN. You do not need to
implement everything from the Application Block. You can howerver pick up
some good pointers.
Regards,

Deepak
[I Code, therefore I am]
"Dave" wrote:
I have two forms, Form1 and Form2. From Form2, how do I reference the value
in a control on Form1?

Or perhaps a more specific question: Form1 contains a textbox with the value
of 10. This form is hidden. Form2 is active and a user enters a value of 2
into a blank text box. How can I add this value to the textbox in Form1 so
that when Form1 is displayed it's textbox displays 12?

I probably have the wrong mindset here; I'm thinking Access where I could
set a reference to a control on another form. Is this the way it's done in
..NET? Or do I need to save everything to variables and refresh each form
when it is activiated?

Nov 16 '05 #2
Thanks Deepak

I see a lot of good examples (Walkthroughs) but I haven't found one that is
right on point. But there is much available that I haven't gone through yet.

What I am trying to do is mimic an Access app that uses a switchboard to
call multiple forms that pass or reference values among themselves.

In short, I need to learn better the concepts of how forms should interact
and maintain state in a Windows .NET app.

If anyone knows of a good example, please let me know.

"Deepak" <De****@discussions.microsoft.com> wrote in message
news:DD**********************************@microsof t.com...
Dave,
A cleaner design will be to create another class which manages your data.
Something based on the MVC pattern. You can find more information on this
in
the User Interface Process Application Block on MSDN. You do not need to
implement everything from the Application Block. You can howerver pick up
some good pointers.
Regards,

Deepak
[I Code, therefore I am]
"Dave" wrote:
I have two forms, Form1 and Form2. From Form2, how do I reference the
value
in a control on Form1?

Or perhaps a more specific question: Form1 contains a textbox with the
value
of 10. This form is hidden. Form2 is active and a user enters a value of
2
into a blank text box. How can I add this value to the textbox in Form1
so
that when Form1 is displayed it's textbox displays 12?

I probably have the wrong mindset here; I'm thinking Access where I could
set a reference to a control on another form. Is this the way it's done
in
..NET? Or do I need to save everything to variables and refresh each
form
when it is activiated?

Nov 16 '05 #3
Hi Dave,

As for the question you mentioned, I think Deepak's suggestion on apply a
MVC pattern is quite reasonable. For such scenario, we need to separate the
data with the displaying UI. Just use the more specific question you
mentioned:
Form1 has txt1 which display the total count

Form2 has txt2 which accept the user's new input

Then, Form1 and Form2 and all the controls on them are the UI, and the
actual data should be maintained in the application in separate place. We
can use a custom class (has a member variable ), for example named
"CountManager" to hold the total count. Then, when the user input new value
in the Form2's txt2 and click OK to submit it. We hide Form2 and update the
value in the custom class, just like:

CountManager.Total + = txt2.newValue;
Form2.Hide

Then, make Form1 visible, that'll fire the Form1's Activate event, and in
this event , we need to update the Form1's UI from the DAta
Store(CountManager.Total).

So this is a general progress of interaction between two forms. We can
abstract the progress as :

User change the UI(input) -----> update the data in data store(in memory
or other storage) ----------> fire event to Refresh UI ------> UI
retrieve updated data from data store and update it self.

Here is the reference on the UI process Application block in MSDN:

#User Interface Process Application Block for .NET
http://msdn.microsoft.com/library/de...us/dnbda/html/
uip.asp

Hope also helps. thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 16 '05 #4
ahh..now I understand better.

Thanks for the insight. And for the link.

Dave


"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:yt**************@cpmsftngxa10.phx.gbl...
Hi Dave,

As for the question you mentioned, I think Deepak's suggestion on apply a
MVC pattern is quite reasonable. For such scenario, we need to separate
the
data with the displaying UI. Just use the more specific question you
mentioned:
Form1 has txt1 which display the total count

Form2 has txt2 which accept the user's new input

Then, Form1 and Form2 and all the controls on them are the UI, and the
actual data should be maintained in the application in separate place. We
can use a custom class (has a member variable ), for example named
"CountManager" to hold the total count. Then, when the user input new
value
in the Form2's txt2 and click OK to submit it. We hide Form2 and update
the
value in the custom class, just like:

CountManager.Total + = txt2.newValue;
Form2.Hide

Then, make Form1 visible, that'll fire the Form1's Activate event, and in
this event , we need to update the Form1's UI from the DAta
Store(CountManager.Total).

So this is a general progress of interaction between two forms. We can
abstract the progress as :

User change the UI(input) -----> update the data in data store(in
memory
or other storage) ----------> fire event to Refresh UI ------> UI
retrieve updated data from data store and update it self.

Here is the reference on the UI process Application block in MSDN:

#User Interface Process Application Block for .NET
http://msdn.microsoft.com/library/de...us/dnbda/html/
uip.asp

Hope also helps. thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 16 '05 #5
You're welcome Dave,

Happy programming and enjoy .net :).

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 16 '05 #6
On Mon, 06 Dec 2004 09:17:11 GMT, v-******@online.microsoft.com (Steven
Cheng[MSFT]) wrote:
... separate the
data with the displaying UI. Just use the more specific question you
mentioned:
...
Then, Form1 and Form2 and all the controls on them are the UI, and the
actual data should be maintained in the application in separate place. We
can use a custom class (has a member variable ), for example named
"CountManager" to hold the total count. Then, when the user input new value
in the Form2's txt2 and click OK to submit it. We hide Form2 and update the
value in the custom class, just like:
...
Then, make Form1 visible, that'll fire the Form1's Activate event, and in
this event , we need to update the Form1's UI from the DAta
Store(CountManager.Total).


A good explanation, to be sure. But I had posed a parallel question
recently. I normally use something analogous to a 'Facade' pattern, but
the main thing that bothered me was that when the number of controls
increases, it becomes impractical to pass the names of individual controls
to the module that is doing the data updates. In that case, you'd really
have to pass a pointer to the entire form.

Ex1: Two textboxes are being updated by a realtime data monitor. Fine...
just create a simple Facade that has pointers to those two controls. The
facade acts like a control panel. Pass a ref to the facade into the
module that retrieves data.

Ex2: But what if the form has 40 controls? The facade no longer
simplifies data flow, and in fact just adds another layer of complexity.
In that case it would seem 'logical' to pass a pointer to the entire form,
but that is not a clean design either, and in fact loses encapsulation.
Nov 16 '05 #7
Hi _BNC ,

Thanks for your join.
As for the problem you mentioned, based on my own understanding, when the
UI changed, it will notify the the model to change , this is done by call
some method on the controller or directory call a Management class's method
which has some parameters that contains the new input values. So that means
the controller or Management class should have no sense of the
UI(controls), they just use the input parameters in their method and use
those params to update the data store. How do you think ?

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 16 '05 #8

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

Similar topics

2
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a main form with a continuous subform. On the main form I have a text box that references a field on the subform. What I'd like it to do is show the value...
1
by: Simon Matthews | last post by:
Hope someone can help an Access beginner! I've just started keeping my surgical logbook on access and it's a simple flat-file affair. I have created several queries that will list cases...
6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
2
by: Stan | last post by:
I have a dataset in one form that I instanciate there. I would like to access that dataset from another form. dim ds as new myds (myds is a dataset on the first form and is generated from a...
6
by: Ken Breit | last post by:
I have an ActiveX control that I would like to make available from any form in my application. I figured the best way was to create a reference to it, and then have a module that will create the...
17
by: Paul Helmuth | last post by:
All, (here's an easy one)... This is probably a stupid question - please bare with me as I am new to dotNet. How does one reference objects on a form from a module? In 6.0 you could simply...
2
by: Miro | last post by:
I am a pure beginner and reading 3 books at the same time trying to learn vb. I have created 2 forms in my "Solution" No where can I see in any of the books how you load / call one form from the...
9
by: Alan | last post by:
Hmmm, I'm not too good with the syntax of referencing a subreport. I have frmInvoice which has the invoice details (e.g. ProductCode, ProductCost etc) in the subform frmInvoiceDetails. I'm trying...
21
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main...
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
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: 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...
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: 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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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.