Filtering a dataview with multiple criteria using Datatimepicker, checkboxes, etc.
Posted on 2006-04-12
This seemed like a fun thing to do but joining the statements got a little confusing since with more than one filter needs an "and" between the filter criteria. I know of one way to do it but it seems like "bad coding" so I want to do it the proper way.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
' Start out clean with no filter.
dv7RowFilter = ""
If cbOneOn.Enabled = True Then
dv7.RowFilter = "Date1 " & cmbOne.Text & " #" & dtOne.Value & "#"
If cbTwoOn.Checked = True Then
dv7.RowFilter = dv.RowFilter.ToString & " AND " & ("Date2 " & cmbTwo.Text & " #" & dtTwo.Value & "#")
If cbThreeOn.Checked = True Then
dv7.RowFilter = dv.RowFilter.ToString & " AND " & ("Date3 " & cmbThree.Text & " #" & dtThree.Value & "#")
This code is retarded and broken. Basically it relies on the first box to be checked. I know another way of doing it but it is archaic and I will not post it here. Basically the form would have one datagrid, three check boxes to activate the datetimepickers, the cmdone,cmdtwo,cmdthree are three combo boxed with '<>=' in there collection. Then the submit button is pushed they should run the rowfilter. I am sure someone in the past has come up with a nifty way to filter down a datagrid with date time boxes, checkboxed, etc.