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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

760 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

21 Experts available now in Live!

Get 1:1 Help Now