ComboBox (DropDown style) Populating with displayed values?

I've recently started trying to learn windows forms and C# at the same time. I've found myself in a rut where i just seem to be blanking out while i'm searching the documentation and have probably gone down a rabbit hole on a very simple problem.

I'm trying to create a combobox (DropDown style) and populate it with items. My understanding is that if you want the ComboBox to have both displayed items and values that are different, you have to create an object to represent this and pass that into the Items.Add method. Also, based what I've read in the docs, if you just pass a string object the ComboBox will use the same string for the DisplayMember and the ValueMember. So I'm doing this:

string string_value = "Foo";

When I execute the application and look at the combobox i can expand it but it only contains blank entries for each item that i have added. However, if I select one of the blank lines, the expected 'Foo' string will show up in the textbox.

I have also tried writing an object with the DisplayMember/ValueMember properties, instantiating the object, setting these two properties and passing that to Items.Add but this results in the same behaviour.

Am I doing something wrong? Could someone post a complete example of populating a dropdown combobox with an arbitrary string/value pair?
LVL 13
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Create new Windows fotms application and add combobox to the form. Double-click form and fill Form1_Load function:

            comboBox1.Items.Add("Item 1");
            comboBox1.Items.Add("Item 2");

Run application and see that Item 1 and Item 2 appear in the dropdown list. ValueMember property is used in data-bound controls.
gripeAuthor Commented:
This didn't work.. it did the same thing. Created a list of blank entries. I have taken screen shots of the process if you'd like to get a visual impression of what I'm seeing:

It's an rtf document zipped.
gripeAuthor Commented:
Note that I didn't change any properties or mess with any other code. I just created a new Windows app, added a comboBox to the form. Double clicked on the form and added the two items you suggested to the form's load event.
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Looks strange. It should work. Can you post your project instead of image?
I usually do it this way:
comboBox1.Items.Add (new ListItem("Item 1", "0"));
comboBox1.Items.Add (new ListItem("Item 2", "1"));

Hope it helps
A lot of people have been having problems similar to yours.  This might be related to Mcafee 8 buffer overrun protection.   You need to disable that if you have it

Try this...

I recently installed McAfee 8 and the buffer overflow protection was the
culprit. Once disabled the messagebox behaved normally. Many thanks to
those who pointed this out.
Hope this helps.  -Aaron

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
If you have Mcafee, you don't need viruses. FDISK and FORMAT.
> If you have Mcafee, you don't need viruses. FDISK and FORMAT.

gripeAuthor Commented:

Thanks, that was exactly the problem. Seems odd that McAfee would cause that type of problem. (I haven't read the links yet, maybe more can be learned there)... As soon as I disabled my (corporately enforced) McAfee Framework service, the problem disappeared.

Thanks for the effort Alex.

No problem.  Yeah, I've heard about a lot of people having this problem.  Its something I've been meaning to look into further also.

Glad it helped.  

There is currently a hot fix from Mcafee. It will not come in on your standalone update engine or your epo as of this post. If you need to apply the hot fix follow this link to microsofts TK on this problem. That will lead you to the latest on where to obtain a fix.;en-us;893708
You will probably have to have a current valid Grant number for you product.
Allen Barge

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

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.