Alec George Doran-Twyford Alec George Doran-Twyford - 7 months ago 16
SQL Question

Visual Studio 2015 Combo Boxes

I am trying to use Combo boxes in a visual studio 2015 (I think this means its VB6 code)

I am trying to build a list of values from a MySQL ADODB.recordset I have been able to insert them into the combo box.

However, I have no idea how to get or set the value in the Combobox.

so cmbGenre.setValue(new Object / id assoiated with a object)
or MsgBox("Current Select value in Combo box is = " & cmbGenre.selectObject)

The objGenre is just a class which has to variable ID & Name (this is all the columns in the MySQL table

Public Sub refreshCmbGenre(ByVal id As Long)
Call rsSetup(TABLE_GENRES)
rsGenres.Sort = FIELD_NAME

Do Until rsGenres.EOF
cmbGenre.Items.Add(New objGenre(rsGenres.Fields(FIELD_ID).Value, rsGenres.Fields(FIELD_NAME).Value))

'=====this is the problem code=========================
rsGenres.Find("[id]=" & id)
cmbGenre.SelectedText = rsGenres.Fields(FIELD_NAME).Value
End Sub


If I understand what you are trying to do, it sounds like you are looking for this:

cmbGenre.SelectedIndex = cmbGenre.FindStringExact(rsGenres.Fields(FIELD_NAME).Value)

This will find the index of the combobox item that matches the field name, and then set the selection that item.

You can then get the values out using


This will return the object bound to the that item, containing both the ID and the FieldName.

This link should help with a better solution for working with comboboxes. It has a similar question in C# but is very easy to convert: