Click here to Skip to main content
15,886,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How can set the value of a combobox item.

i want to set the text and value of a combobox item.


so that when i get the selecteditem .i can easily get the value of the item.
But while displaying i display text.

I tried making an object of combobox but it shows blank with a messagebox
Posted

 
Share this answer
 
I think this is pretty much the same question together with a solution posted: http://stackoverflow.com/questions/2023316/c-sharp-winforms-combobox-with-label-and-value[^]

cbo is your ComboBox, myData contains the values:
var data = myData.Select(oneData => new {
     Value = oneData.Value, Text = oneData.Name}).ToList();
cbo.ValueMember = "Value";
cbo.DisplayMember = "Text";
cbo.DataSource = data;
 
Share this answer
 
v2
ComboBox[^] has many properties to achieve that:
- SelectedIndex[^]
- SelectedItem[^]
- SelectedText[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900