Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27252

VS 2008 [RESOLVED] ComboBox with a two column datasource, find combobox index of item with key = mykey

$
0
0
Hi!

Please help.
I have a combobox with datasource set to a two column DataTable with id and title. Displaymember is title, valuemember is id.
Code:

Dim myOleDBCommand As New OleDbCommand()
            myOleDBCommand.Connection = newConn
            myOleDBCommand.CommandText = "select id, title from company where is_buyer <> 0 order by title"
            Dim myTable As New DataTable
            Dim myOtherFillAdapter As New OleDbDataAdapter(myOleDBCommand)
            myOtherFillAdapter.Fill(myTable)
            If myTable.Rows.Count > 0 Then
                With cmbBuyer
                    .DataSource = myTable
                    .DisplayMember = "title"
                    .ValueMember = "id"
                End With
            End If

I can't find a way, how I could find the combobox.index of the item with a selected id.
I need to set the combobox to a specific value based on other selections. I try to get a function like this:
Code:

Function SelectComboID(ByRef c As System.Windows.Forms.ComboBox, ByRef ID As Object) As Object
        Dim i As Integer
        If c.Items.Count = 0 Then Exit Function
        For i = 0 To c.Items.Count - 1
            If c.Items(i).Value = ID Then
                c.SelectedIndex = i
                Exit Function
            End If
        Next i
    End Function


Viewing all articles
Browse latest Browse all 27252

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>