Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Setting the comboBox text

Posted on 2003-11-25
4
Medium Priority
?
255 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 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

926 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