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

Access public methods in multple copies of the same form

Hi All,

I have multiple copies of the same form open in an app. (These are not MDI
child forms).
I then open a summary form that displays data from each of the previously
open forms.
I have a number of public methods inside the child forms. How do I iterate
thru each child form and run the public method in each?

cheers,
Mark Chimes


--------------------------------------------------------------------------------
I am using the free version of SPAMfighter for private users.
It has removed 1840 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!
Jan 26 '07 #1
7 1561
When you create and destroy the forms, keep track of them in a
collection somewhere (perhaps with a WeakReference so that you don't
accidentally keep them alive if the form is otherwise dead). There is
also the Application.OpenForms property (which you could enumerate,
testing each to see if it is of the correct tye), but I prefer to keep
strick track myself - this allows for a range of tricks (improved
separation, no constant testing, indexing and type checking all come
to mind).

Marc
Jan 26 '07 #2
Hi Marc,

I am using...
string someVariable = Application.OpenForms[i].Controls[j].Controls[k].Text

to gain access to the contents of controls in these forms.

How do I run a public method of this form? For example, I have a pubic
method called ChangeMap(string strState) that I need to call from the main
form.

cheers,
Mark

"Marc Gravell" <ma**********@gmail.comwrote in message
news:%2******************@TK2MSFTNGP06.phx.gbl...
When you create and destroy the forms, keep track of them in a collection
somewhere (perhaps with a WeakReference so that you don't accidentally
keep them alive if the form is otherwise dead). There is also the
Application.OpenForms property (which you could enumerate, testing each to
see if it is of the correct tye), but I prefer to keep strick track
myself - this allows for a range of tricks (improved separation, no
constant testing, indexing and type checking all come to mind).

Marc
--------------------------------------------------------------------------------
I am using the free version of SPAMfighter for private users.
It has removed 1841 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!
Jan 26 '07 #3


On Jan 26, 3:30 pm, "Mark Chimes" <markchi...@gmail.comwrote:
Hi Marc,

I am using...
string someVariable = Application.OpenForms[i].Controls[j].Controls[k].Text

to gain access to the contents of controls in these forms.
Ugh. That's the nasty way to do it. Much nicer to make properties in
your Form class that return meaningful values and know where to look
them up. For example:

public string CustomerName
{
get { return this.CustomerNameTextBox.Text; }
}
How do I run a public method of this form? For example, I have a pubic
method called ChangeMap(string strState) that I need to call from the main
form.
Well, if you're using the OpenForms list, and you're looking for forms
of class MyForm3, you could do this:

MyForm3 f3 = Application.OpenForms[i] as MyForm3;
if (f3 != null)
{
string customerName = f3.CustomerName;
f3.ChangeMap("....");
}

The "as" operation and the "if (f3 != null)" allow for other types of
forms being open, but you want only the MyForm3 type forms.

Jan 27 '07 #4
Bruce, thank you.

This is the kind of info I've been looking for. :-)

One other question (for now).
When my app runs, it auto-opens an MDIChild (WebForm) that contains a couple
of JPG maps on individual WebBrowser controls. These maps arew "hot-spotted"
by using HTML code. When the user clicks on a section of the map, a MyForm
opens with data for that section.
I have multiple copies of MyForm open (between 2 - 20).
I also have a SummaryFrm open (called from the MainApp menu) that grabs a
couple of variables from each open MyForm and displays and then calculates
and displays summaries.
So far so good.

I need SummaryFrm to iterate thru the open MyForms and run a public method
inside MyForm.
I can see this public method easily enough from WebForm, but not from
SummaryFrm. I understand that SummaryFrm has no direct relationship with
MyForm so how do I get the data specific to each MyForm back into
SummaryFrm?

cheers,
Mark

"Bruce Wood" <br*******@canada.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
>

On Jan 26, 3:30 pm, "Mark Chimes" <markchi...@gmail.comwrote:
>Hi Marc,

I am using...
string someVariable =
Application.OpenForms[i].Controls[j].Controls[k].Text

to gain access to the contents of controls in these forms.

Ugh. That's the nasty way to do it. Much nicer to make properties in
your Form class that return meaningful values and know where to look
them up. For example:

public string CustomerName
{
get { return this.CustomerNameTextBox.Text; }
}
>How do I run a public method of this form? For example, I have a pubic
method called ChangeMap(string strState) that I need to call from the
main
form.

Well, if you're using the OpenForms list, and you're looking for forms
of class MyForm3, you could do this:

MyForm3 f3 = Application.OpenForms[i] as MyForm3;
if (f3 != null)
{
string customerName = f3.CustomerName;
f3.ChangeMap("....");
}

The "as" operation and the "if (f3 != null)" allow for other types of
forms being open, but you want only the MyForm3 type forms.
--------------------------------------------------------------------------------
I am using the free version of SPAMfighter for private users.
It has removed 1841 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!
Jan 27 '07 #5


On Jan 26, 9:26 pm, "Mark Chimes" <markchi...@gmail.comwrote:
One other question (for now).
When my app runs, it auto-opens an MDIChild (WebForm) that contains a couple
of JPG maps on individual WebBrowser controls. These maps arew "hot-spotted"
by using HTML code. When the user clicks on a section of the map, a MyForm
opens with data for that section.
I have multiple copies of MyForm open (between 2 - 20).
I also have a SummaryFrm open (called from the MainApp menu) that grabs a
couple of variables from each open MyForm and displays and then calculates
and displays summaries.
So far so good.

I need SummaryFrm to iterate thru the open MyForms and run a public method
inside MyForm.
I can see this public method easily enough from WebForm, but not from
SummaryFrm. I understand that SummaryFrm has no direct relationship with
MyForm so how do I get the data specific to each MyForm back into
SummaryFrm?
Won't the Application.OpenForms thing work for you? I have to admit
that I've never tried it; I've never needed to do that.

Another possibility, as Marc pointed out, is to maintain your own list
in some central place. Here's an example:

Inside WebForm:

private static ArrayList _myForms = new ArrayList();

public static IEnumerable GetMyFormList()
{
return _myForms;
}

public static void AddMyForm(MyForm form)
{
_myForms.Add(form);
}

public static void RemoveMyForm(MyForm form)
{
_myForms.Remove(form);
}

Then, from within MyForm:

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
WebForm.AddMyForm(this);
}

protected override void OnClosed(EventArgs e)
{
base.OnClosed(e);
WebForm.RemoveMyForm(this);
}

Then, from anywhere in your application, you should be able to say,

foreach (MyForm f in WebForm.GetMyFormList())
{
... do something ...
}

Jan 27 '07 #6
Bruce,

OK, the penny has dropped :-)

Rather than using the Application.OpenForms (which only handles forms opened
from the main app and not child or sub-child forms), I should be building my
own list which allows me to add/delete whenever I need to.

Just one further question :-)
protected override void OnLoad()... how does this method affect myexisting
OnLoad() method?
I realise I could simply take the code and place it inside my OnLoad method,
but I would rather understand what the "override" does.

cheers,
Mark

--------------------------------------------------------------------------------
I am using the free version of SPAMfighter for private users.
It has removed 1841 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!
Jan 28 '07 #7


On Jan 28, 5:56 am, "Mark Chimes" <markchi...@gmail.comwrote:
Bruce,

OK, the penny has dropped :-)

Rather than using the Application.OpenForms (which only handles forms opened
from the main app and not child or sub-child forms), I should be building my
own list which allows me to add/delete whenever I need to.

Just one further question :-)
protected override void OnLoad()... how does this method affect myexisting
OnLoad() method?
I realise I could simply take the code and place it inside my OnLoad method,
but I would rather understand what the "override" does.
If you have already overridden OnLoad, then just add the code in
there. If you already have an OnLoad method with that same signature,
then it must say "override", because it is replacing the OnLoad method
of the System.Windows.Forms.Form base class. If you create an OnLoad
method with that same signature and you don't say "override" (or
"new") then the compiler will complain.

Jan 28 '07 #8

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

Similar topics

3
by: Random Person | last post by:
Does anyone know how to use VBA to relink tables between two MS Access databases? We have two databases, one with VBA code and the other with data tables. The tables are referenced by linked...
5
by: Robert | last post by:
Hello Accessors I have some reports created in Access that are very good for what they do. However, it seems to me that when you are displaying information you don't need to print out that a...
5
by: Colin Anderson | last post by:
I discovered, with great excitement, this article http://www.davison.uk.net/vb2notes.asp when researching methods for emailing from Access via Notes. Unfortunatly, when I run this I get a...
7
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I...
11
by: Grasshopper | last post by:
Hi, I am automating Access reports to PDF using PDF Writer 6.0. I've created a DTS package to run the reports and schedule a job to run this DTS package. If I PC Anywhere into the server on...
0
by: Lauren Quantrell | last post by:
I use this code in my Access 2K apps to check for multple instances of my Access2K apps and it works fine on XP and WIn2K OS. However, trying it on Access 2003/ XP OS it doesn't work and gets...
4
by: Daylor | last post by:
hi. i have multi thread application in vb.net is there a way NET support, so i can mark the class , to be access only for 1 thread each time ? if there is , small sytax sample will help ...
5
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callnetfrcom.asp The Joy of Interoperability Sometimes a revolution in programming forces you to abandon all...
4
by: =?Utf-8?B?c2lwcHl1Y29ubg==?= | last post by:
Hi I have a user control that is designed as below. I am creating these User Controls Dynamically in another form. They are multiple types of User Controls all with a common Interface so I can...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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
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
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...

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.