Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 7th, 2006, 03:20 AM
Authorized User
Join Date: Jun 2006
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default calling control in one form from another form

hi all,

i have two forms in a C#.net windows application

i have a list view control in form1.

i want to fill this list view from form2 and display form1 from form2.

any idea of doing this?
thanks in advance
Reply With Quote
  #2 (permalink)  
Old November 7th, 2006, 06:20 PM
Friend of Wrox
Join Date: May 2006
Location: San Diego, CA, USA.
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts

It is almost always a bad idea to manipulate a control on one form from another form.

However, if you want to do this directly, you merely need to change the access modifier in
the declaration for the listview in form2 from private to public.

Then you can reference the listview from the first form where you instantiate and display the form. Still, I want to make it very clear that this is commonly regarded as a very bad programming practice.

A better solution is to let the second form populate its own listview. There are numerous ways to do this, but one common way is to provide a method on the second form that is used to pass the list that you want displayed (by list here, I mean the array, dataset, or whatever you are going to use to populate the listview). For a dialog form, you would control all the behavior of populating the listview, showing the form, and then finally returning any required values to the first form as needed. There are other ways as well.

To go a step further, however, it would be worthwhile looking into a model/view/controller or other more decoupled architecture to investigate some better solutions.

Woody Z http://www.learntoprogramnow.com
Reply With Quote
  #3 (permalink)  
Old November 8th, 2006, 07:35 AM
Authorized User
Join Date: Jun 2006
Location: , , .
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts

thanks a lot woodyz.i have found a solution for that problem.thanks again
Reply With Quote
  #4 (permalink)  
Old November 8th, 2006, 10:05 AM
Authorized User
Join Date: Feb 2006
Location: Bluefields, , .
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to MAKO

Hi Netfresher, I've had the same problem with a windows form project. Could you be so kind to help me find the solution as you did? Thanks.

MAKO - "El super simio"
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get the current calling form in a class? littlekitty ASP.NET 2.0 Basics 0 October 17th, 2006 08:28 PM
calling functions form another window geogomez Javascript How-To 2 November 29th, 2005 07:20 AM
Calling a procedure embeded in another form lryckman Access VBA 6 April 29th, 2005 08:48 AM
Addressing a control on a form from another form Lamprey Access 1 March 3rd, 2005 12:05 AM
calling a form melvik C# 4 July 23rd, 2003 05:24 AM

All times are GMT -4. The time now is 05:03 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.