Accessing a Listbox from another Class?

D

David

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
 
G

Greg Ewing [MVP]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top