Solved

Filtering a DataView with a combination of criteria

Posted on 2004-08-17
3
249 Views
Last Modified: 2010-04-23
Hi,

I have a Windows with
- a DataGrid (dgr) bound to a DataView (dv),
- 5 ComboBoxes cboVehicle, cboDriver, cboProject, cboUtilisation and cboUser
- 2 DateTimePickers (dtp1 and dtp2) that give the minimum and maximum date to filter the "DateDep" field in the data

dv.RowFilter = "Vehicle_ID = '" & cboVehicle.SelectedValue & "'" works perfectly to filter with a single combo and
dv.RowFilter = "DateDep >= '" & dtp1.Text & "'" and dv.RowFilter = "DateDep <= '" & dtp2.Text & "'" work also separately.

My questions are:

1. How combine (including syntax) several (including all) criteria in the RowFilter method or any other method to filter my data with;
2. How to deal with the event that 1, several or all the ComBoxes may be blank (Text property = " ")  (Remark " " not "")

Any help shall be greatly appreciated.
0
Comment
Question by:Ghanisen
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 500 total points
Comment Utility
1. dv.RowFilter = "DateDep >= '" & dtp1.Text & "'"  & " AND DateDep <= '" & dtp2.Text & "'" & " AND Vehicle_ID = '" & cboVehicle.SelectedValue & "'" etc..

2. I'm not quite sure what you mean, but if you mean to ignore the ones that are " " then do someting like this

dim StrFilter as string

if cbodriver.selectedvalue <> "" then
    strfilter = "driver_id = '" & cbodirver.selectvalue & "' AND "
end if
if cbovehicle.selectvalue <> " " then
   strfilter += "vehicle_id = '" & cbovehicle.selectedvalue "' AND "
end if
etc....

if strfilter.length > 1 then
            StrFilter = StrFilter.Substring(0, StrFilter.Length - 5)
end if
0
 
LVL 25

Expert Comment

by:RonaldBiemans
Comment Utility
sorry forgot one line

dv.rowfilter = strfilter
0
 

Author Comment

by:Ghanisen
Comment Utility
Hi Ronald

Thanks very much for your help which got me very close to the final solution which I post for those who might be interested:

Dim strFilter As String

        If cboVehicule.Text <> "" Then
            strFilter = "Vehicle_ID = '" & cboVehicle.SelectedValue & "' AND "
        End If

        If cboDriver.Text <> "" Then
            strFilter += "Driver_ID = '" & cboDriver.SelectedValue & "' AND "
        End If

        If cboProject.Text <> "" Then
            strFilter += "Project_ID = '" & cboProject.SelectedValue & "' AND "
        End If

        If cboUtilisation.Text <> "" Then
            strFilter += "Utilisation = '" & cboUtilisation.Text & "' AND "
        End If

        If cboUser.Text <> "" Then
            strFilter += "User_ID = '" & cboUser.SelectedValue & "' AND "
        End If

        strFilter += "DateDep >= '" & dtp1.Text & "' AND "

        strFilter += "DateDep <= '" & dtp2.Text & "''"

        If strFilter.Length > 1 Then
            strFilter = strFilter.Substring(0, strFilter.Length - 1)
        End If

        dvTrajet.RowFilter = strFilter

        'afficher le nombre d'enregistrements du DataGrid dand le label "lblCount"
        lblCount.Text = "" & dgr.VisibleRowCount & "  enregistrements affichés"
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now