473,769 Members | 1,994 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 2056

"JimC" <ji**@nospam.pl s> wrote in message
news:uU******** ***********@new ssvr13.news.pro digy.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.pl s> wrote in message
news:mQ******** ***********@new ssvr21.news.pro digy.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 "alternativ e" 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
5935
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 terminated by pressing ++ and then terminate the process. I searched the entire internet and found out that there could be two things wrong (both of them are mentioned in the bug list on the access
7
1683
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 Subform First subform is a subform of Main Form, and Second Subform is a subform of First Subform.
6
4753
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 appreciated. Thanks in advance
4
1644
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 look through two tables and return the appropriate matches. This will be very small scale at the beginning but once I get everything working it will include more tables and dozens of matches to be returned. I would like the information to print...
49
14354
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 application is relatively big: around 200 tables, 200 forms and sub-forms, 150 queries and 150 repports, 5GB of data (SQL Server 2000), 40 users. I'm wondering what are the disadvantages of using Access as front-end? Other that it's not...
0
1871
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 pattern after the same form used in the MS template, "Event Management.mdb" application that is downloaded from the MS Template Gallery on their website. I narrowed down the problem to the Control Source in the, "Attendees_Subform using the...
12
2930
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 gen.aspx.vb and uc.ascx.vb. With simple html or self contained vb in the user control, everything is fine and dandy. So the next stage is to pass back a simple variable from the user control to the host page. I used VS.NEt to create the files.
9
4496
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 like to know is the stability, speed & ease of use of both the products. I believe Access 2007 has a new file format too and that it may be slower.
0
9420
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,...
0
10035
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9984
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
9851
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6662
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
5293
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
3949
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
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.