• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 531
  • Last Modified:

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.
0
directxBOB
Asked:
directxBOB
  • 3
  • 2
3 Solutions
 
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
 
AcumentalityCommented:

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

Open in new window

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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now