Reputation: 89
Okay..So, I was trying to create a filter on the datagrid using comboboxes. I was able to create a filtration process for only one combo box. What I wanted to do is to filter the filtered data in the datagrid but i don't know how. I already tried some ways that I thought could solve the issue but, no luck so far. Basically I have 4 combo boxes for the filtration. For example, the first combo box is for Province then I still want to filter the search into Municipality then to Districts and to Years. So, the user will be able to sort or filter his search from the database.
This is are the codes that I'm stock on. The code for the Year is actually giving me a system.int32 error. so I'm still fixing it. It's just the same code actually.
Thanks for the help.!
Try
Dim view As New DataView(dataset)
view.RowFilter = String.Format("PENRO like '%{0}%'", ComboBox1.SelectedItem)
DataGridView1.DataSource = view
Catch ex As Exception
MsgBox(ex.Message)
End Try
Try
Dim view As New DataView(dataset)
view.RowFilter = String.Format("CENRO like '%{0}%'", ComboBox2.SelectedItem)
DataGridView1.DataSource = view
Catch ex As Exception
MsgBox(ex.Message)
End Try
Try
Dim view As New DataView(dataset)
view.RowFilter = String.Format("DISTRICT like '%{0}%'", ComboBox7.SelectedItem)
DataGridView1.DataSource = view
Catch ex As Exception
MsgBox(ex.Message)
End Try
Upvotes: 0
Views: 1650
Reputation: 333
Why don't you concatenate the values of the filters?
For example:
view.RowFilter = String.Format("DISTRICT like '%{0}%'", ComboBox7.SelectedItem) & " AND " & _
String.Format("CENRO like '%{0}%'", ComboBox2.SelectedItem)
I don't usually use String.Format, I prefer using custom made string, but it should work.
Upvotes: 0