Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Setting the comboBox text

Posted on 2003-11-25
4
Medium Priority
?
254 Views
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
0
Comment
Question by:ab0u110a
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 3

Accepted Solution

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

comboBox1.SelectedIndex=0;

This will sjhow your first item.


Good Luck!
0
 
LVL 20

Assisted Solution

by:TheAvenger
TheAvenger earned 160 total points
ID: 9823330
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
 

Author Comment

by:ab0u110a
ID: 9823361
Thanks Both of you
0
 
LVL 3

Expert Comment

by:magnus23
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.
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

730 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