Solved

Setting the comboBox text

Posted on 2003-11-25
4
250 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
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
magnus23 earned 100 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 40 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

837 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