0

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..

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Lee21
0

>Filter my Datatable through combobox

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

0
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..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.