Violeta Popa

Violeta Popa

  • NA
  • 137
  • 161.2k

filter datagridview

Apr 7 2013 6:10 AM
 Hello :) I have a column in my datagridview named perioada(datatype: string) which has values of this form: 10/3/2012-10/2/2013.
 Then, I have two datetimepikers and I want to filter my dgv like this:
if perioada's values are       10/3/2012-10/2/2013
                                      11/3/2012-11/2-2013
                                               ...
if dtp1's value is: 11/2/2012
and dtp2's value is: 11/3/2013

i want the dgv to show only the records where the second date(the bolded) is between 11/2/2012 and 11/3/2013. Hope it makes sense what i've explained.And i did sth like that:

politaGridView.DataSource = dataSet.Tables["obtine"].DefaultView;
                        int i = politaGridView.CurrentRow.Index;
                        string temp = politaGridView.Rows[i].Cells[6].Value.ToString();
                        string[] array = temp.Split('-');
                        DateTime date = DateTime.Parse(array[1]);
                        if (date >= dateTimePicker1.Value && date <= dateTimePicker2.Value)
                        {
                            //do what?
                        }

Answers (1)