Solved

C# ComboBox Text & Values

Posted on 2009-05-08
6
504 Views
Last Modified: 2012-05-06
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
Comment
Question by:directxBOB
  • 3
  • 2
6 Comments
 
LVL 16

Assisted Solution

by:CuteBug
CuteBug earned 300 total points
ID: 24334818
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
 
LVL 1

Accepted Solution

by:
Acumentality earned 200 total points
ID: 24335019

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

Open in new window

0
 

Author Comment

by:directxBOB
ID: 24335035
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 16

Assisted Solution

by:CuteBug
CuteBug earned 300 total points
ID: 24335215
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
 

Author Comment

by:directxBOB
ID: 24335595
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
 

Author Comment

by:directxBOB
ID: 24362063
Any ideas how to do this via Code?
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

786 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