I use Visual Studio 2012. I put the contain of an excel file in a DataGridView . I have 2 comboboxes in the form (CmbBxPorteurSelect and CmbBxTypePASelect). I want to filter the DataGridView columns with the item selected in each combobox (the values of the 2 combobox are in different column: column "Porteur" for CmbBxPorteurSelect and column "Statut" for CmbBxTypePASelect). The filtring dos not run correctly. Can some one help? Find down my code in VB.
Thank you for help.
A.KOTE
ali.kote@orange.sn
What I have tried:
The code which I wrote for filter DataGridView columns.
Private Sub Connect2Excel(ByVal chemin As String, ByVal lasource As String)
constr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & chemin & ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1;'"
con = New OleDbConnection(constr)
sda = New OleDbDataAdapter("Select * From [" & lasource & "$]", con)
dt = New DataTable
sda.Fill(dt)
DtGrdVwListePAs.DataSource = dt
End Sub
Private Sub CmbBxPorteurSelect_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CmbBxPorteurSelect.SelectedIndexChanged
Dim DV As DataView = New DataView(dt)
DV.RowFilter = String.Format("[Porteur] LIKE '%{0}%'", CmbBxPorteurSelect.Items)
If CmbBxPorteurSelect.SelectedIndex <> -1 Then
DtGrdVwListePAs.DataSource = DV
End If
End Sub
Private Sub CmbBxTypePASelect_SelectedIndexChanged(sender As Object, e As EventArgs) Handles CmbBxTypePASelect.SelectedIndexChanged
Dim DV As DataView = New DataView(dt)
DV.RowFilter = String.Format("[Statut] LIKE '%{0}%'", CmbBxTypePASelect.Items)
If CmbBxPorteurSelect.SelectedIndex <> -1 Then
DtGrdVwListePAs.DataSource = DV
End If
End Sub