Probably the simplest (and clearest way) is to only insert into the
trailers
if the time is not contained in the list of lunchtimes. For example:
var timesToAvoid = (List<string>)dataGridView2.DataSource;
var trailers = new List<trailer__time>();
for (var i = 0; i < trailer_count; i++)
{
calculated_start_time = calculated_start_time.AddMinutes(i == 0 ? 0 : minutes_apart);
if (!timesToAvoid.Contains(calculated_start_time.ToString("HH:mm")))
{
trailers.Add(new trailer__time
{
Trailer_Number = i,
Delivery_Time = calculated_start_time.ToString("HH:mm")
});
}
}
dataGridView1.DataSource = trailers;
If dataGrideView1 only listed the potential delivery times and not the trailer_number as well, it would be even simpler by using the Except method...
var timesToAvoid = (List<string>)dataGridView2.DataSource;
var altMethod = new List<string>();
for (var i = 0; i < trailer_count; i++)
{
calculated_start_time = calculated_start_time.AddMinutes(i == 0 ? 0 : minutes_apart);
altMethod.Add(calculated_start_time.ToString("HH:mm"));
}
dataGridView1.DataSource = altMethod.Except(timesToAvoid);