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 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
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
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
"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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |