Solved

C# ComboBox Text & Values

Posted on 2009-05-08
6
502 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What .NET website keeps me current? 9 52
install app on other machine 13 32
Split string on commas but not when enclosed in parentheses 7 47
Run time Error 4 34
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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