iterate through items in a comobox to match values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mfaisalwarraich
    New Member
    • Oct 2007
    • 194

    iterate through items in a comobox to match values

    Hello,

    I am trying to match the values of a combo box which are typed inside a combo box with the comb box items, which are bind to a datasource. i can see the items in the combo box and if i get the selecteditem its working fine means nothing is wrong with the connection and other things.

    but when im trying to match the values im getting this error:

    System.Data.Dat aRowView

    and this error continues to display equal to the number of rows inside table. im using the following code:
    Code:
    Public Class admForm
        Dim itm As Object
        Dim result As String
    
        Private Sub admForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'admDataSet.tblAdm' table. You can move, or remove it, as needed.
            Me.TblAdmTableAdapter.Fill(Me.admDataSet.tblAdm)
    
        End Sub
    
        Private Sub cboAdm_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboAdm.LostFocus
    
            For Each itm As Object In cboAdm.Items
                result = itm.ToString()
                If result <> Me.cboAdm.Text Then
                    MsgBox(result)
                End If
            Next
    
        End Sub
    End Class
    i have already set the display member of the combo box. everything is done from the property sheet using visual studio. i just want to match the text against the items of the combo box. for example in pseudo code


    if comboBox.text <> combobox.items. item then
    ''add into the database

    end if

    here i just need to check if the typed values are already in the combo box's items collection. please tell me how i can check this.

    thanx
  • mfaisalwarraich
    New Member
    • Oct 2007
    • 194

    #2
    now im using a different approach by filling in the items into the combobox. here is the code:
    Code:
    Public Class admForm
        Dim itm As Object
        Dim result As String
        Dim ds As DataSet
        Dim dt As New DataTable
    
        Private Sub admForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'admDataSet.tblAdm' table. You can move, or remove it, as needed.
            Me.TblAdmTableAdapter.Fill(Me.admDataSet.tblAdm)
            dt = admDataSet.tblAdm
            For Each s As String In dt.Rows.Item(0).Item("fruit")
            ComboBox1.Items.Add(s)
            Next
        End Sub
     
     End Class
    the above code fill the comobox with the following value:
    a
    p
    p
    l
    e

    because the first row in the fruit column is "apple". please tell me how i can fill the combobox with the column values.
    thanx

    Comment

    Working...