如何在datagride中排除时间 [英] How to exclude time in datagride

查看:95
本文介绍了如何在datagride中排除时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢您的时间



我有2个Datagrids dg1填充交付时间。 dg2的午餐时间需要从dg1中排除。经过几天的研究,我找不到一个很好的例子。建议请。



我尝试了什么:



Days



研究



数组

Thank you for your time

I have 2 Datagrids dg1 populates times for deliveries. dg2 has lunch times that needs to be excluded from dg1. After days of research i cant find a good example. Suggestions please.

What I have tried:

Days
of
research
on
array

推荐答案

如果午餐时间列表中没有包含时间,可能最简单(也是最清晰的方法)是只插入预告片。例如:

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;



如果dataGrideView1只列出了潜在的交付时间而不是trailer_number,那么使用Except方法会更简单...


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&lt;string&gt;)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);


这篇关于如何在datagride中排除时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆