473,320 Members | 1,991 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.

access from one inherited to the other inherited class

Hi,
I have a class structure like this:

rootform : System.Windows.Forms.Form
midiform : rootform
child1 : rootform
child11 : child1
child2 : rootform
chld21 : child2

there is an instance of child11 and child21. when user selects a record
in child21 (like a part inventory), it should pass the part# to child11
(call a public method in child11). in child21, how do I have access to
child11? I tried to find it in System.Windows.Forms.Form but it just
give me the active form (Form.ActiveForm).

user in midiform menubar can open child11 and child21 as many as the
want. so there is no garantee that when user select a record in child21,
I have child11 opened. so I should detect it in the collection (if not
found, open it). is there a forms collection that I can trace it and
find a form? how I should deal with this kind of situation?

thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
6 1291
Hi,

Nothing keeps track of the opened form. You need to do that by yourself. For
example you can keep one class with static Register and Unregister methods
and then when the form is created in the root form constructor (or probably
Load event would be better place) you can call Register. For unregistering
you can use Form's closed event

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"newbie_csharp" <an*******@devdex.com> wrote in message
news:OI**************@TK2MSFTNGP14.phx.gbl...
Hi,
I have a class structure like this:

rootform : System.Windows.Forms.Form
midiform : rootform
child1 : rootform
child11 : child1
child2 : rootform
chld21 : child2

there is an instance of child11 and child21. when user selects a record
in child21 (like a part inventory), it should pass the part# to child11
(call a public method in child11). in child21, how do I have access to
child11? I tried to find it in System.Windows.Forms.Form but it just
give me the active form (Form.ActiveForm).

user in midiform menubar can open child11 and child21 as many as the
want. so there is no garantee that when user select a record in child21,
I have child11 opened. so I should detect it in the collection (if not
found, open it). is there a forms collection that I can trace it and
find a form? how I should deal with this kind of situation?

thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #2
thanks Stoticho. I thought so. I will use an array in rootform to keep
the name of the forms. but how can I access to them? form example when I
am in child21 and I know that child11 is already opened, how do I have
access to it?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
how about having a collection of Form type in rootform? all instances
should be a member of my collection. then I will have access to the
other members from any form. if C# doesn't have a collection for forms,
I guess my collection should work. is that right?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
Hi,
That's why I suggested static register. If you put it in the rootform you
need to find a reference to it unless again this is not static.
How to identify the forms in the collection.... Well, you can use dictionary
(key/value collection) look at Hashtable for example. Each form you should
give an unique name (key). If only one instance of a form exists you can use
the Type object as a key.
If dictionaries doesn't work for you you need to enumerate the collection
and find the target form from some other critera

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"newbie_csharp" <an*******@devdex.com> wrote in message
news:uy**************@TK2MSFTNGP14.phx.gbl...
thanks Stoticho. I thought so. I will use an array in rootform to keep
the name of the forms. but how can I access to them? form example when I
am in child21 and I know that child11 is already opened, how do I have
access to it?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #5
Stoitcho,

thanks for your help. it worked. now I can send a parameter form a form
to another form and change the focus to that. so I don't need more than
that. but there is one thing I am curious about it and I couldn't find
it. I add the form to the dictionary as the value. if the child has a
public method, I don't have access to it from the other form. for
example child11 has "mymethod()" public method. in child21, I can use
"focus()" of child11 but I don't have access to "mymethod()". I know
why, because the type of the value in dictionary is "Form", not child11
but it could be nice to this ability. is there any trick for doing this?

thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #6
Hi,

The trick is to cast the object in the dictionary to the class you want. Of
course you need somehow to know what the real type of the object. If you
don't know the type of the object there is not much you can do about it.

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"newbie_csharp" <an*******@devdex.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Stoitcho,

thanks for your help. it worked. now I can send a parameter form a form
to another form and change the focus to that. so I don't need more than
that. but there is one thing I am curious about it and I couldn't find
it. I add the form to the dictionary as the value. if the child has a
public method, I don't have access to it from the other form. for
example child11 has "mymethod()" public method. in child21, I can use
"focus()" of child11 but I don't have access to "mymethod()". I know
why, because the type of the value in dictionary is "Form", not child11
but it could be nice to this ability. is there any trick for doing this?

thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #7

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

Similar topics

9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
1
by: Siemel Naran | last post by:
Do using declarations respect private, protected, public access levels? class A { public: void f(); private: void f(int); }; class B : public A {
1
by: Dave | last post by:
Hello NG, Regarding access-declarations and member using-declarations as used to change the access level of an inherited base member... Two things need to be considered when determining an...
6
by: Alf P. Steinbach | last post by:
#include <iostream> struct Belcher { int x; void belch() { std::cout << x << std::endl; } Belcher( int anX ): x( anX ) {} }; struct Person: private Belcher { Person(): Belcher( 666 ) {} };
11
by: Noah Coad [MVP .NET/C#] | last post by:
How do you make a member of a class mandatory to override with a _new_ definition? For example, when inheriting from System.Collections.CollectionBase, you are required to implement certain...
3
by: Jeff User | last post by:
Hello I am using C#, .net1.1 Vis Studio 2003 I am using homeBase.aspx.cs page as a base for several other aspx/aspx.cs web pages. The base page handles some operations that are common to all...
8
by: Tapeesh | last post by:
I have a following piece of code. The code was compiled using g++ class A { public : virtual void fn() = 0; }; class B: virtual private A {
6
by: Roka | last post by:
Hi all why cann't I access protected var from a inherited class? Code example: class Base{ protected: int color; public: virtual void show() = 0; };
14
by: lovecreatesbea... | last post by:
Could you tell me how many class members the C++ language synthesizes for a class type? Which members in a class aren't derived from parent classes? I have read the book The C++ Programming...
3
by: rick | last post by:
I have a situation where I want to write an extensible class that is capable of saving / restoring properties of classes derived from it. A simplified example is explained as follows;- class A...
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: 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...
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
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.