[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 27092
  • Last Modified:

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";
comboBox1.Items.Add(string_value);

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?
0
gripe
Asked:
gripe
  • 3
  • 3
  • 3
  • +2
1 Solution
 
AlexFMCommented:
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.
0
 
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:

http://www.icenine.ca/vs-fu.zip

It's an rtf document zipped.
0
 
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
AlexFMCommented:
Looks strange. It should work. Can you post your project instead of image?
0
 
nhewitt21Commented:
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
0
 
AaronReamsCommented:
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...

http://www.dotnet247.com/247reference/msgs/58/292324.aspx

<snip>
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.
</snip>
 
Hope this helps.  -Aaron
0
 
AlexFMCommented:
If you have Mcafee, you don't need viruses. FDISK and FORMAT.
0
 
AaronReamsCommented:
> If you have Mcafee, you don't need viruses. FDISK and FORMAT.

eh?
0
 
gripeAuthor Commented:
Aaron:

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.

gripe
0
 
AaronReamsCommented:
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.  

Cheers,
Aaron
0
 
allinbCommented:
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.
http://support.microsoft.com/default.aspx?scid=kb;en-us;893708
You will probably have to have a current valid Grant number for you product.
Regards,
Allen Barge

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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