Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Call ComboBox from another class

combobox

  • Please log in to reply
3 replies to this topic

#1 LiLMsNinja

LiLMsNinja

    CC Regular

  • Just Joined
  • PipPipPip
  • 42 posts

Posted 05 December 2009 - 08:08 PM

Is it not possible to populate a ComboBox from another class other than the Form1.cs class?
  • 0

#2 FlashM

FlashM

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 82 posts

Posted 05 December 2009 - 11:06 PM

Of course it is possible... You just need to have a reference to your combo box.
  • 0

#3 LiLMsNinja

LiLMsNinja

    CC Regular

  • Just Joined
  • PipPipPip
  • 42 posts

Posted 06 December 2009 - 07:32 AM

I kind of thought by doing:

Form1 f = new Form1

Then marking the combobox as public, i could use:
f.combobox.datasource = ablahblahblah

But NOOOO. It's gathering everything just fine but when it reports back to Form1 all my hard work dispears into no mans land.
  • 0

#4 gaylo565

gaylo565

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 258 posts

Posted 07 December 2009 - 08:09 AM

The way you are describing should work as long as you dont close your Form1 instance when you open the new class. If that is the case then you need to save the instance of Form1 as a variable and modify the variable's properties instead of the class properties.
example:
public static Form1 formHolder = null;
Form1 f = new Form1;
formHolder = f;
then use formHolder variable like so:
Form1.formHolder.combobox.datascource = ablahblahblah;
Form1.formHolder.Show();

  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download