473,503 Members | 12,175 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trying to access control on one from from another form

On my main form in a C# program, I create an instance of another form that
contains a ListView control, in the usual way, that is:

public class frmMain : System.Windows.Forms.Form
{

// [...]

InfoForm myInfoForm = new InfoForm( );
myInfoForm.Show ( );

// [...]
}
When I click on the ListView on myInfoForm, I want to
be able to access two or three controls on the main form which
have public access (or can be changed easily to have public
access).

Seems like a simple enough requirement, similar to everything else
I do in C#, but I can't quite make this happen. Anyone know how?

Jim



Jan 28 '06 #1
4 2038

"JimC" <ji**@nospam.pls> wrote in message
news:uU*******************@newssvr13.news.prodigy. com...
On my main form in a C# program, I create an instance of another form that
contains a ListView control, in the usual way, that is:

public class frmMain : System.Windows.Forms.Form
{

// [...]

InfoForm myInfoForm = new InfoForm( );
myInfoForm.Show ( );

// [...]
}
When I click on the ListView on myInfoForm, I want to
be able to access two or three controls on the main form which
have public access (or can be changed easily to have public
access).

Seems like a simple enough requirement, similar to everything else
I do in C#, but I can't quite make this happen. Anyone know how?

Jim


The title of the thread should be

"Trying to access control on one *form* from another form."
Sorry for the typo which almost seems de rigueur in an unintended way.

Jim
Jan 28 '06 #2
Pass a reference to your main form in the constructor of your InfoForm.
--
Dale Preston
MCAD C#
MCSE, MCDBA
"JimC" wrote:
On my main form in a C# program, I create an instance of another form that
contains a ListView control, in the usual way, that is:

public class frmMain : System.Windows.Forms.Form
{

// [...]

InfoForm myInfoForm = new InfoForm( );
myInfoForm.Show ( );

// [...]
}
When I click on the ListView on myInfoForm, I want to
be able to access two or three controls on the main form which
have public access (or can be changed easily to have public
access).

Seems like a simple enough requirement, similar to everything else
I do in C#, but I can't quite make this happen. Anyone know how?

Jim



Jan 28 '06 #3
I wrote:
On my main form in a C# program, I create an instance of another form
that
contains a ListView control, in the usual way, that is:

public class frmMain : System.Windows.Forms.Form
{

// [...]

InfoForm myInfoForm = new InfoForm( );
myInfoForm.Show ( );

// [...]
}
When I click on the ListView on myInfoForm, I want to
be able to access two or three controls on the main form which
have public access (or can be changed easily to have public
access).

Seems like a simple enough requirement, similar to everything else
I do in C#, but I can't quite make this happen. Anyone know how?

Dale responds:
Pass a reference to your main form in the constructor of your InfoForm.

Yes, of course. Thanks, Dale! I was making the common mistake of
creating a field of type Form in my InfoForm class, rather than
a field of type frmMain. Works fine now.

Just for the heck of it -- if it ain't broke, then break it -- would like
to implement an alternate approach by creating an event and a
delegate. I'll report back to this thread next time I'm on.

Jim

Jan 29 '06 #4

"JimC" <ji**@nospam.pls> wrote in message
news:mQ*******************@newssvr21.news.prodigy. com...
I wrote:
On my main form in a C# program, I create an instance of another form
that
contains a ListView control, in the usual way, that is:

public class frmMain : System.Windows.Forms.Form
{

// [...]

InfoForm myInfoForm = new InfoForm( );
myInfoForm.Show ( );

// [...]
}
When I click on the ListView on myInfoForm, I want to
be able to access two or three controls on the main form which
have public access (or can be changed easily to have public
access).

Seems like a simple enough requirement, similar to everything else
I do in C#, but I can't quite make this happen. Anyone know how?


Dale responds:
Pass a reference to your main form in the constructor of your InfoForm.

Yes, of course. Thanks, Dale! I was making the common mistake of
creating a field of type Form in my InfoForm class, rather than
a field of type frmMain. Works fine now.

Just for the heck of it -- if it ain't broke, then break it -- would like
to implement an alternate approach by creating an event and a
delegate. I'll report back to this thread next time I'm on.

Jim


The "alternative" is what you should start with.

Your current solution makes your subform untestable and unusable without
your main form and makes your main form harder to maintain because a
maintainer has to know that parts of the form are being changed from
outside.
Jan 29 '06 #5

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

Similar topics

3
5918
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
7
1671
by: Julia Baresch | last post by:
Hi everyone, My company recently upgraded from Office 97 to Office XP. As those who've read my other posts know I have a database with 3 nested subforms Main form-->First Subform-->Second...
6
4712
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
4
1629
by: Alex | last post by:
I have searched the boards but I have not found what I am looking for yet. I have a form with two combo boxes. When the user makes a selection in both of the combo boxes the information will...
49
14282
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
0
1839
by: jphelan | last post by:
I have a subform that works fine until you import it into a new database when it crashes if you try to open it in either disign or form view. The form, "Attendees_Subform" in my application was...
12
2912
by: Phil Certain | last post by:
Hi, I'm trying to do something very simple...or at least it should be. I have created a host page (gen.aspx) and a very simple user control (us.ascx). The corresponding code-behind files are...
9
4473
by: prakashwadhwani | last post by:
Hi !! I'm about to develop a new project for a client. Should I go about it in Access 2003 or 2007 ? Purchasing it either for me or for my client is not a major consideration here ... what I'd...
0
7067
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
7264
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
7316
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
6975
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
7449
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
3160
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...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
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 ...
1
728
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.