2015-10-16 62 views
-7

我有大約42個列表框。我正在使用dragdrop並拖動輸入進行計劃。檢查列表框中的某個項目是否已經存在於許多其他列表框中?

樣品:

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)); 
    } 
} 

我應該在哪裏把該錯誤消息,以便它不會複製數據。

+6

你忘了C#5.0和C#6.0 – Steve

+2

只有5個標籤是允許的,他不希望被遺漏的人感到孤獨。 –

+0

嗨,大家好,我很抱歉,我沒有注意到我的標籤。你對我的問題有什麼想法嗎? – LogronJ

回答

0

只在42個列表框的每一箇中添加那些尚未添加的項目。

不需要錯誤消息。

if (!listBox1.Items.Contains(e.Data.GetData(DataFormats.Text)))  
      listBox1.Items.Add(e.Data.GetData(DataFormats.Text)); 
相關問題