Click here to Skip to main content
15,908,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to filter a datagridview between dates and times

What I have is a start and End Date and start and end time. On my form I have a date textbox and time that are the current time and date. So when the form opens I want to filter the datagridview where the enddate is less than or equal to the date textbox and then starttime and endtime are between the time textbox. I have this so far

VB
Dim value10 As String = Me.DateTextBox.Text
        Dim value11 As String = Me.TimeTextBox.Text


Me.TblShiftBindingSource.Filter = "StartDate <= '" & value10 & "' and EndDate >= '" & value10 & "' and StartTime <= '" & value11 & "' and EndTime > '" & value11 & "'"
Posted

1 solution

Here is an example:
Filter data dispalyed in a DataGridView using BindingSource and DataView[^]

Hope it helps.
Regards
Espen Harlinn
 
Share this answer
 
Comments
Sandeep Mewara 8-Jan-11 14:46pm    
Comment from OP:
My filter works except for the hours part. If I say Smith ends at 1300 and the time is anything starting with 13 (lets say 1305) he will still show as on even though he is off.

Date - 01/08/2011 Time - 1305


Name StartDate STime EndDate ETime
Smith 01/08/2011 0700 01/08/2011 1300
wiswalld 8-Jan-11 14:49pm    
My filter works except for the hours part. If I say Smith ends at 1300 and the time is anything starting with 13 (lets say 1305) he will still show as on even though he is off.

Date - 01/08/2011 Time - 1305


Name StartDate STime EndDate ETime
Smith 01/08/2011 0700 01/08/2011 1300
Espen Harlinn 9-Jan-11 6:17am    
Try converting input from strings to DateTime

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900