I have just finished some code that is successfully filtering deadlines that fall between 2 datetimepickers – startSchedule and endSchedule.
At the moment the if statement is initiated when I want it to be but I’m not sure which code to put in the if statement to display the filtered rows in the datagridview.
The datagridview has the following columns – module, description, deadline, priority.
How do I display the appropriate rows in the if statement that meet the conditions.
Let me know if you need any more information, thankyou.
Here is the code I have so far:
private void scheduleButton_Click(object sender, EventArgs e)
{
DateTime startSchedule = startDate.Value.Date;
DateTime endSchedule = endDate.Value.Date;
foreach (DataGridViewRow dr in TaskTable2.Rows)
{
string deadline = dr.Cells["Deadline"].Value.ToString();
DateTime deadlineRow = Convert.ToDateTime(deadline);
if (startSchedule <= deadlineRow && deadlineRow <= endSchedule)
{
MessageBox.Show("Display Row"); // display filtered rows here.
}
}
}
Depends on how you have your DataGridView setup. Ideally you would probably do this from the SQL side of things, but you can do it this way if you prefer.
Perhaps just hide the row if your ifstatement is NOT met:
Let me know if I am misunderstanding what you want.