guyz help me. I want to filter the data that's being displayed to my datagrid once I click the combobox and select a specific value,the selected value will be the item to filter the data that I needed to be displayed in the datagrid.. I'm using a datatable,a combobox and a datagrid..here's my code

------------------------------------------------------------------------
Private Sub cboView_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboView.Click

        dt = New DataTable
        sda = New SqlDataAdapter("SELECT DISTINCT KPIPOSTCODE FROM KKPIGROUP", sqlcon)
        sda.Fill(dt)

        If dt.Rows.Count <> 0 Then

            cboView.DataSource = dt
            cboView.DisplayMember = dt.Columns(0).ColumnName
            Call ref()

        Else
        End If

    End Sub
'''here is function ref
------------------------------------------------------------------------------------
Public Sub ref()

        dt = New DataTable
        sda = New SqlDataAdapter("SELECT * FROM KKPIGROUP where KPIPOSTCODE = '" & cboView.text & "' ", sqlcon)
        sda.Fill(dt)
        If dt.Rows.Count = 0 Then
        Else
            dg.DataSource = dt
            dg.Enabled = True
        End If

    End Sub

I hope you help me..

Recommended Answers

All 2 Replies

>Filter my Datatable through combobox

Call ref() method in the handler of SelectedIndexChanged event of ComboBox.

Private Sub cboView_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboView.SelectedIndexChanged
         Call ref()
    End Sub

I've tried what you've said but there is something wrong happened. The item in the combobox were not the same.. Please see attached screenshot..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.