Solved

C# ComboBox Text & Values

Posted on 2009-05-08
6
498 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
Comment Utility
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
Comment Utility

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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 16

Assisted Solution

by:CuteBug
CuteBug earned 300 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Any ideas how to do this via Code?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now