Un'altra soluzione è quella di crearti un DataTable e associarlo alla combo.
codice:
Dim dt As DataTable
Dim row As DataRow
Private Sub SetDataTable()
dt = New DataTable
With dt
.TableName = "catagoria"
.Columns.Add("id", System.Type.GetType("System.Int32"))
.Columns.Add("categoria", System.Type.GetType("System.String"))
End With
SetComboCategoria()
End Sub
Private Sub SetComboCategoria()
cmbCategoria.DataSource = dt
cmbCategoria.DisplayMember = "categoria"
cmbCategoria.ValueMember = "id"
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
SetDataTable()
End Sub
per popolare la combo:
codice:
For x As Int32 = 1 To 10
row = dt.NewRow
row("id") = x
row("categoria") = "categoria " & x.ToString
dt.Rows.Add(row)
Next
e il valore selezionato lo leggi sfruttando la SelectedValue: cmbCategoria.SelectedValue.ToString