Setting the comboBox text

I use this statements to  populate a combobox


foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
                        comboBox1.Items.Add (printer);


How can i make the first item in a combobox be the first printer,

I thought i could use

this.comboBox1.Text = "";

and somehow get the first item to be displayed e.g when the program runs the first printer found will be the selected item in the combo box


Thanks for your help
ab0u110aAsked:
Who is Participating?
 
magnus23Commented:
HI ab0u110a !
After your code place this line

comboBox1.SelectedIndex=0;

This will sjhow your first item.


Good Luck!
0
 
TheAvengerCommented:
I would write:

if (comboBox1.Items.Count > 0)
  comboBox1.SelectedIndex=0;

This will not fail if there is NO printer installed on the system, while the code from magnus23 will.
0
 
ab0u110aAuthor Commented:
Thanks Both of you
0
 
magnus23Commented:
Of course! But i've presented just a local solution and not the complete code. At any time there should be always error cheking.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.