If your
dataGridView1
is bound to
DataSource
through
bindingSource1,
then use the following code in
ValueChanged
event of
DateTimePicker
control, to filter the
BindingSource,
to show only those records which have the date selected in the
DateTimePicker
.
private void dateTimePicker1_ValueChanged(object sender, EventArgs e) {
bindingSource1.Filter = string.Format("EventDate = #{0}#", dateTimePicker1.Value.ToLongDateString());
}
If you have inserted the date into database in text format, say using
ToShortDateString()
of
DateTimePicker
, then use the same text format in the filter string of
bindingSource1
using ' instead of #, as below
private void dateTimePicker1_ValueChanged(object sender, EventArgs e) {
bindingSource1.Filter = string.Format("EventDate = '{0}'", dateTimePicker1.Value.ToShortDateString());
}