C# ComboBox Text & Values

Using the Items collection for a combobox how do I assign Text and Values to it via the editor (or via the designer code for that matter).

eg:

this.products.Items.Add("BW");

BW is the value
where the text would be be: Black&White

I would like to manually add these values as there is not enough to create a collection etc.
directxBOBAsked:
Who is Participating?
 
AcumentalityCommented:

this.products.Items.Add("BW");
this.products.selectedIndex = this.products.Items.Count-1;
this.products.selectedValue = "Black&White";

Open in new window

0
 
CuteBugCommented:
When you add the combo box via the designer, you will see a small black triangle on the top right corner of the combo box.
Click on that.
Click on "Edit Items".
Now add your items (one item per line)
0
 
directxBOBAuthor Commented:
Great, and out of interest how do I do this in the Designer Code just so I know how to do it for future reference.

Cheers
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
CuteBugCommented:
If you add it via the Designer, it will automatically add the required code in the Designer code.
You need not edit the Designer code directly.
0
 
directxBOBAuthor Commented:
Ok, but for my own knowledge (and given that I can't get edit items up on this control) how do I do this via code?
0
 
directxBOBAuthor Commented:
Any ideas how to do this via Code?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.