Setting the comboBox text

Posted on 2003-11-25
Last Modified: 2010-04-16
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
Question by:ab0u110a
  • 2

Accepted Solution

magnus23 earned 100 total points
ID: 9820241
HI ab0u110a !
After your code place this line


This will sjhow your first item.

Good Luck!
LVL 20

Assisted Solution

TheAvenger earned 40 total points
ID: 9823330
I would write:

if (comboBox1.Items.Count > 0)

This will not fail if there is NO printer installed on the system, while the code from magnus23 will.

Author Comment

ID: 9823361
Thanks Both of you

Expert Comment

ID: 9823843
Of course! But i've presented just a local solution and not the complete code. At any time there should be always error cheking.

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem with SqlConnection 4 160
COnsume rest client 6 36
How to get the web content with different encodings 2 27
Data is not showing from images 15 37
Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now