Accessing a Listbox from another Class?

  • Thread starter Thread starter David
  • Start date Start date
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
 
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.
 
Back
Top