Hi, I am a new one to vb 2005. I dont know how to filter the datagridview with the 2 datetimepicker control one for start date and another one for end date. I want to search the dates based on the datevalue of the data in one coloumn.

Any one can help me?
Thanks in advance.

6 Years
Discussion Span
Last Post by M.Waqas Aslam

Is the DataGridView Bound or Unbound , could you please be more specific , and if you can post the code to fill your datagridview


>I dont know how to filter the datagridview with the 2 datetimepicker control

You can filter the datasource easily using DataView.

Create an instance of System.Data.DataView

Dim dt as new  DataTable
// You have to populate the datatable instance

 Dim dv as DataView =new DataView(dt)


Filter your data,

dv.RowFilter="StartDate>='" + dateTimepicker1.value + "' and EndDate<='" + dateTimepicker2.value + "'"

Edited by __avd: n/a


Yes Its databound control which I have used. Kindly let me know how can i filter the date value in my data with datetimepickers.

Thanks in advance


I think it is working. but it will takes the database month as date.
Can U tell me where I made a mistake?


appear a problem when i use this code :

dv.RowFilter="StartDate>='" + dateTimepicker1.value + "' and EndDate<='" + dateTimepicker2.value + "'"

the message :
cannot find Collum StartDate, and cannot find Collum EndDate

Somebody knows what is happening?


as the error suggests your datagridview doesn't have a column named startdate and a column named enddate.

You should change the filter to match the columns you want to filter:

dv.RowFilter="your_column_here>='" + dateTimepicker1.value + "' and your_column_here<='" + dateTimepicker2.value + "'"

You can use 2 columns like adatapost's sample or filter the same one.


hi !
if u r using sql db to populate ur grid then use this code

dim mycon as new sqlconnection("ur connection string ")
dim ds as new dataset()
dim da as new sqldataadapter("select * from table1 where fielddate >=" & datetimepicker_from.value.date & "and fielddate<="&datetimepicker_to.value.date,mycon)
datagridview.datasource = ds.table("mytable")

this code only shows the record between from and to date , given by the user ,
hope this will helpful for u,
M.Waqas Aslam

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.