Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 检查列表框中的项目是否已存在于许多其他列表框中?_C#_Winforms - Fatal编程技术网

C# 检查列表框中的项目是否已存在于许多其他列表框中?

C# 检查列表框中的项目是否已存在于许多其他列表框中?,c#,winforms,C#,Winforms,我有大约42个列表框。我正在使用dragdrop和DragEnter创建日程表 样本: private void listBox1_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.Text)) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None;

我有大约42个列表框。我正在使用dragdrop和DragEnter创建日程表

样本:

private void listBox1_DragEnter(object sender, DragEventArgs e)
{
    if (e.Data.GetDataPresent(DataFormats.Text))
        e.Effect = DragDropEffects.Copy;
    else
        e.Effect = DragDropEffects.None;
}

private void listBox1_DragDrop(object sender, DragEventArgs e)
{

    if (listBox1.Items.Contains(e.Data.GetData(DataFormats.Text)))
    {
        MessageBox.Show("Duplicate");

    }
    else
    {
        listBox1.Items.Add(e.Data.GetData(DataFormats.Text));
    }
}

我应该将该错误消息放在哪里,以便它不会复制该数据。

在42个列表框中的每个列表框中只添加那些尚未添加的项目

不需要任何错误消息

 if (!listBox1.Items.Contains(e.Data.GetData(DataFormats.Text)))    
            listBox1.Items.Add(e.Data.GetData(DataFormats.Text));

你忘了C#5.0和C#6.0只允许5个标签,他不想让被遗漏的那个感到孤独。嗨,伙计们,很抱歉我没有注意到我的标签。你们知道我的问题吗?