473,728 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Update one form from another

Hi

In a c# Windows Forms application (not asp.net) if I've opened 2 or
more non-modal forms using code like:

FormTypeA aForm = new FormTypeA();
aForm .Show();

FormTypeB bForm = new FormTypeB();
bForm .Show();
How do I update a control (e.g. label) in aForm from code in bForm?
And will the update be seen immediately, or on activation?

John South
www.wherecanwego.com
Pangbourne UK

Feb 18 '06 #1
4 2034
bob
Hi John,
Suggest you use events to communicate between forms.

If formA instantiates FormB then
Declare a custom event (say MySpecialEvent) in FormB with the payload that
you want to deliver.

Declare your FormB variable at FormA Class Level and write a
FormB.MySpecial Event Eventhandler.

The update will occur when events are handled. Depending on where you are in
your code you may have to issue a DoEvents to get a timely update.
If both FormA and FormB are instantiated in FormC then you can still use the
same technique by FormC responding to FormA and then raising an Interrrupt
which is responded to by FormB
Have a look at
http://www.codeproject.com/csharp/eventarguments.asp
HTH.
Bob
"JohnSouth" <Jo**********@g mail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi

In a c# Windows Forms application (not asp.net) if I've opened 2 or
more non-modal forms using code like:

FormTypeA aForm = new FormTypeA();
aForm .Show();

FormTypeB bForm = new FormTypeB();
bForm .Show();
How do I update a control (e.g. label) in aForm from code in bForm?
And will the update be seen immediately, or on activation?

John South
www.wherecanwego.com
Pangbourne UK

Feb 18 '06 #2
I'll second bob - events are the most elegant way here.

I shouldn't be posting this, but there is a 'hacky' way to do it
(particularly if you're not familiar with events in .NET). Remember,
Forms are objects - so just add a get accessor, (or a method if you
need to do a whole lotta stuff) to the FormTypeA class, and construct
your bForm passing aForm as a parameter. You can update it before it is
shown, or whenever you like then.

FormTypeA aForm = new FormTypeA();
aForm .Show();

FormTypeB bForm = new FormTypeB(aForm );
// Constructor: public FormTypeB(FormT ypeA form)

string newvalue = "test";

bForm.MyAFormOb jectProperty.Ch angeLabel(newva lue); // Updates the value
bForm .Show();

However, this is poor programming practice and I strongly suggest
events! Once you understand them, they're unbelieveably cool and make
programming far more flexible :)

bob wrote:
Hi John,
Suggest you use events to communicate between forms.

If formA instantiates FormB then
Declare a custom event (say MySpecialEvent) in FormB with the payload that
you want to deliver.

Declare your FormB variable at FormA Class Level and write a
FormB.MySpecial Event Eventhandler.

The update will occur when events are handled. Depending on where you are in
your code you may have to issue a DoEvents to get a timely update.
If both FormA and FormB are instantiated in FormC then you can still use the
same technique by FormC responding to FormA and then raising an Interrrupt
which is responded to by FormB
Have a look at
http://www.codeproject.com/csharp/eventarguments.asp
HTH.
Bob
"JohnSouth" <Jo**********@g mail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi

In a c# Windows Forms application (not asp.net) if I've opened 2 or
more non-modal forms using code like:

FormTypeA aForm = new FormTypeA();
aForm .Show();

FormTypeB bForm = new FormTypeB();
bForm .Show();
How do I update a control (e.g. label) in aForm from code in bForm?
And will the update be seen immediately, or on activation?

John South
www.wherecanwego.com
Pangbourne UK


Feb 18 '06 #3
What's 'hacky' about that and why is it 'poor programming practice'?
<st*********@nt lworld.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
I'll second bob - events are the most elegant way here.

I shouldn't be posting this, but there is a 'hacky' way to do it
(particularly if you're not familiar with events in .NET). Remember,
Forms are objects - so just add a get accessor, (or a method if you
need to do a whole lotta stuff) to the FormTypeA class, and construct
your bForm passing aForm as a parameter. You can update it before it is
shown, or whenever you like then.

FormTypeA aForm = new FormTypeA();
aForm .Show();

FormTypeB bForm = new FormTypeB(aForm );
// Constructor: public FormTypeB(FormT ypeA form)

string newvalue = "test";

bForm.MyAFormOb jectProperty.Ch angeLabel(newva lue); // Updates the value
bForm .Show();

However, this is poor programming practice and I strongly suggest
events! Once you understand them, they're unbelieveably cool and make
programming far more flexible :)

bob wrote:
Hi John,
Suggest you use events to communicate between forms.

If formA instantiates FormB then
Declare a custom event (say MySpecialEvent) in FormB with the payload
that
you want to deliver.

Declare your FormB variable at FormA Class Level and write a
FormB.MySpecial Event Eventhandler.

The update will occur when events are handled. Depending on where you are
in
your code you may have to issue a DoEvents to get a timely update.
If both FormA and FormB are instantiated in FormC then you can still use
the
same technique by FormC responding to FormA and then raising an
Interrrupt
which is responded to by FormB
Have a look at
http://www.codeproject.com/csharp/eventarguments.asp
HTH.
Bob
"JohnSouth" <Jo**********@g mail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
> Hi
>
> In a c# Windows Forms application (not asp.net) if I've opened 2 or
> more non-modal forms using code like:
>
> FormTypeA aForm = new FormTypeA();
> aForm .Show();
>
> FormTypeB bForm = new FormTypeB();
> bForm .Show();
>
>
> How do I update a control (e.g. label) in aForm from code in bForm?
> And will the update be seen immediately, or on activation?
>
> John South
> www.wherecanwego.com
> Pangbourne UK
>

Feb 18 '06 #4
Stephany,
Beats me! Certainly events are more flexible, but if it "ain't broke", then
don't fix it!
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Stephany Young" wrote:
What's 'hacky' about that and why is it 'poor programming practice'?
<st*********@nt lworld.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.com...
I'll second bob - events are the most elegant way here.

I shouldn't be posting this, but there is a 'hacky' way to do it
(particularly if you're not familiar with events in .NET). Remember,
Forms are objects - so just add a get accessor, (or a method if you
need to do a whole lotta stuff) to the FormTypeA class, and construct
your bForm passing aForm as a parameter. You can update it before it is
shown, or whenever you like then.

FormTypeA aForm = new FormTypeA();
aForm .Show();

FormTypeB bForm = new FormTypeB(aForm );
// Constructor: public FormTypeB(FormT ypeA form)

string newvalue = "test";

bForm.MyAFormOb jectProperty.Ch angeLabel(newva lue); // Updates the value
bForm .Show();

However, this is poor programming practice and I strongly suggest
events! Once you understand them, they're unbelieveably cool and make
programming far more flexible :)

bob wrote:
Hi John,
Suggest you use events to communicate between forms.

If formA instantiates FormB then
Declare a custom event (say MySpecialEvent) in FormB with the payload
that
you want to deliver.

Declare your FormB variable at FormA Class Level and write a
FormB.MySpecial Event Eventhandler.

The update will occur when events are handled. Depending on where you are
in
your code you may have to issue a DoEvents to get a timely update.
If both FormA and FormB are instantiated in FormC then you can still use
the
same technique by FormC responding to FormA and then raising an
Interrrupt
which is responded to by FormB
Have a look at
http://www.codeproject.com/csharp/eventarguments.asp
HTH.
Bob
"JohnSouth" <Jo**********@g mail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
> Hi
>
> In a c# Windows Forms application (not asp.net) if I've opened 2 or
> more non-modal forms using code like:
>
> FormTypeA aForm = new FormTypeA();
> aForm .Show();
>
> FormTypeB bForm = new FormTypeB();
> bForm .Show();
>
>
> How do I update a control (e.g. label) in aForm from code in bForm?
> And will the update be seen immediately, or on activation?
>
> John South
> www.wherecanwego.com
> Pangbourne UK
>


Feb 19 '06 #5

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

Similar topics

0
2779
by: Sue Adams | last post by:
I actually have two issues/questions: I have an autonumber field in an access db table that I grab and later use to update a record in another table withing the same db. The code I use to get it from the db table is: ''Retrieve the Registration Identification Number strRegisterID = Rs("Register_ID") Prior to testing my code and actually updating the db, I''m trying to write it to the page to make sure their isn''t a loop or massive...
1
1554
by: Primerov | last post by:
Why i cannot update from another form? I have an update function called UpdateData that works otherwise,but not from another form. Why is it so? I am trying to update tables from the form F1.There i have the following code : DoCmd.OpenForm " F2" UpdateData
4
26200
by: N. Graves | last post by:
Hello... thank you for your time. I have a form that has a List box of equipotent records and a sub form that will show the data of the equipment select from the list box. Is it possible to make a change in the name field in the details, then refresh the list box with new name? Please help and thanks!
3
3792
by: Vinay | last post by:
Hello I am trying to update a Progress bar on a form. I am able to update it via using a simple clock timer, but as soon as I perform a long operation G1 (generation of a report) in a separate form, it stops updating it, but keeps on incrementing the Progress bar values in the background and displays the updated Pbar after finishing the operation G1. My requirement is that it should update during the execution of operation G1. On...
15
3303
by: Darren | last post by:
Help, i want to run an update query from a form.. and was wonderin.. Can the update query run if i want to update a value manually inputted from a form (e.g. !!) to a table (tblPasswordMgmt.Password) but based on a criteria which is neither the two values. Instead it's like (!!=tblPasswordMgmt.UserID).
1
8501
by: Mark Reed | last post by:
Hi All, I'm having a problem with the following code. I've read quite a lot of old posts regarding the issue but none seem to affer a solution. The scenario is. I have a bound form which contains a couple of memo fields. I need to keep some sort of log as to when each update of the memo field occurs so I have locked bot the memo fields on the main form. To edit them, the user double clicks the ememo field which then opens an unbound...
5
2596
by: Stephen Plotnick | last post by:
I'm very new to VB.NET 2003 Here is what I have accomplished: MainSelectForm - Selects an item In a public class I pass a DataViewRow to ItemInformation1 Form ItemInformation2 Form
4
5043
by: Ryan | last post by:
I've got a little bit of code that runs when you enter data in a datasheet view (which is a subform of the form you are in) if rst!DateReceived >= 30 Then Forms!DisposalRecords.Label90.Caption = (Date - rst!DateReceived) & " Days" however, when that runs to update the caption, it says that it cannot find form DisposalRecords
0
3236
by: Access Programming only with macros, no code | last post by:
ERROR MESSAGE: Could not update; currently locked by another session on this machine. BACKGROUND I have the following objects: Table1 - HO (which has about 51,000+ records) Table2 - Contact (which has 68,000+ records)
16
3508
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for renaming the duplicate records? My thinking was to take the results of the duplicate query, and somehow have it number each line where there is a duplicate (tried a groups query, but "count" won't work), then do an update query to change the duplicate to...
0
8891
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8753
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9188
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8110
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6704
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6012
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3229
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2642
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.