Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ComboBox item selection by code

Status
Not open for further replies.

RSfromCO

Programmer
May 3, 2002
149
US
I have a ComboBox that is using objects. Each object has a data value (an integer), and a Text value (a string). The text values are what is displayed in the ComboBox.

As I scroll through my database, each record has an integer representing the data value. I want the ComboBox to display the Text item that matches that data value.

For example, my ComboBox objects might have...
Data Text
1 Cold
5 Warm
8 Hot

Each record in the database contains 1, 5 or 8.

I want the ComboBox to display "Cold", "Warm", or "Hot"

My question is... when I come to a record in the database with the data value 5. How do I select the item in the ComboBox that has data value 5 and have it update to show that item ("Warm") in the ComboBox?
 
Simply grab the index of the item you are trying to select then set the selected index to the index number that you pulled.

Something like so


ComboBox1.SelectedIndex = ComboBox1.FindStringExact("Blow")


Have fun with it. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
If you keep your objects in something that supports the IList interface (like a Dataset or Array, etc.) then you can just simply bind the combobox to it. You would set the ValueMember of the combo to the number and the DisplayMember to the text.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top