How can my comboBox1 be visible inside another class?

  • Thread starter Thread starter trint
  • Start date Start date
T

trint

I get this error:
"WindowsApplication1.Form1.comboBox1' denotes a 'field' where a 'class'
was expected"
when I do this inside a separate class:
"comboBox1.DisplayMember="SourceName";

PaperSource pkSource;
for (int i = 0; i < pd.PrinterSettings.PaperSources.Count; i++)
{
pkSource = pd.PrinterSettings.PaperSources;
comboBox1.Items.Add(pkSource);"
Thanks,
Trint
 
The best way to do this is to add a public method for each operation you
want to expose on that class...
eg. for this case

// inside the class containing the combo box
public void AddComboBoxItem ( object item )
{
comboBox1.Items.Add ( item );
}

// from the outside class that contains an instance of Form1.
Form1 myForm = new Form1();
myForm.AddComboBoxItem ( "Horray" );
myForm.AddComboBoxItem ( "Horrah" );

hope that helps.
 
Back
Top