Link to home
Start Free TrialLog in
Avatar of Frost_Trunks
Frost_Trunks

asked on

Setting ComboBox item values?

How do you set a combobox item's value?
It is a simple dropdownlist that has four selections, but I want to assign a numerical association to the text when it is selected.
I figured I would just add the items to the collection through the form designer.  Usually there is a "Text" property and a "value" property for each item.  Even when I tried to add it through code I couldn't figure it out.

Example:
John > 1
Amanda > 2
Todd > 3
SOLUTION
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rstomar
rstomar

You can create a ListItem Object and add it to combobox as follows :
                     Dim listItem As New System.Web.UI.WebControls.ListItem
                    listItem.Text = "All"
                    listItem.Value = 0
                    li.Selected = True
                    cmbCategories.Items.Insert(0, li)   ' you can call Add instead of Insert


Dim listItem As New System.Web.UI.WebControls.ListItem
                    listItem.Text = "All"
                    listItem.Value = 0
                    listItem.Selected = True
                    cmbCategories.Items.Insert(0, listItem)

sorry forgot to replace li with listItem in all placesin my previous post.
Avatar of Frost_Trunks

ASKER

rstomar:  Will this work within a windows application?  
Frost_Trunks,

Have you check my link to some PAQ question ? It's for windows form application.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok...I found a sample whcih already has this, check this link :

http://www.mgbrown.com/PermaLink37.aspx
jpaulino: Code would work, but not exactly what I was looking for.
rstomar: Creating the class works perfectly, thanks!