Jump to content

Call ComboBox from another class

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
LiLMsNinja

LiLMsNinja

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
Is it not possible to populate a ComboBox from another class other than the Form1.cs class?
CodeMonkey +15 | CommunicationSkills -34 | ClarityUsingEnglish -55 | Clarity while pointing at the monitor and making vigorous facial expressions, occasional grunts, and mouth clicks +150

#2
FlashM

FlashM

    Learning Programmer

  • Members
  • PipPipPip
  • 90 posts
Of course it is possible... You just need to have a reference to your combo box.

#3
LiLMsNinja

LiLMsNinja

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
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.
CodeMonkey +15 | CommunicationSkills -34 | ClarityUsingEnglish -55 | Clarity while pointing at the monitor and making vigorous facial expressions, occasional grunts, and mouth clicks +150

#4
gaylo565

gaylo565

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 268 posts
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();