By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,666 Members | 1,413 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,666 IT Pros & Developers. It's quick & easy.

Accessing a Listbox from another Class?

P: n/a
I have a windows form listbox in one class and I need to reference it
in another class, eg. I need to add an item to the listbox. What is
the correct way to setup the listbox and then set a pointer to pass to
my sub-class. I tried to define a listbox in my new class and then
code:

class.listbox = this.listbox;

The compiled said OK but I had an exception when I attempted to access
the
listbox from the sub_class.

Note. This is not a internal class but a new class under the main
namespace.

Thanks
P.S. Can this even be done. No one at my company has tried this
Nov 13 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
David, you need to pass an instance of your form class to your second class.
Once you have that instance you will have access to the listbox.

--
Greg Ewing [MVP]
http://www.claritycon.com/
"David" <db*******@comcast.net> wrote in message
news:8q********************************@4ax.com...
I have a windows form listbox in one class and I need to reference it
in another class, eg. I need to add an item to the listbox. What is
the correct way to setup the listbox and then set a pointer to pass to
my sub-class. I tried to define a listbox in my new class and then
code:

class.listbox = this.listbox;

The compiled said OK but I had an exception when I attempted to access
the
listbox from the sub_class.

Note. This is not a internal class but a new class under the main
namespace.

Thanks
P.S. Can this even be done. No one at my company has tried this

Nov 13 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.