2009-12-11 101 views
1

您好我有這個程序我試着做列表框以及如何對所選項目執行操作

但我現在想添加一個選項刪除項目(只有選定的)。

thanx提前

+0

的症狀有哪些工作?什麼是不工作呢?平均數是否錯誤? – 2009-12-11 15:48:07

+0

其實我做了平均它現在與我合作...我添加avg代碼 – Tony 2009-12-11 15:49:30

+0

我試過這個刪除的東西,但它不工作 listBox1.SelectedItems.Clear(); – Tony 2009-12-11 15:54:36

回答

1

選中要刪除的項目:

while (listBox1.SelectedIndices.Count > 0) 
    listBox1.Items.RemoveAt(listBox1.SelectedIndices[0]);
+0

一個好的Smart One thanx jon – Tony 2009-12-11 16:19:29

0
protected void Button2_Click(object sender, EventArgs e) 
{ 
    for(int i = ListBox1.Items.Count -1; i>=0; i--) 
    { 
     if (ListBox1.Items[i].Selected) 
     { 
      ListBox1.Items.Remove(ListBox1.Items[i]); 
     } 
    } 
} 

這應該也刪除

+0

listBox1.Items是一個ObjectCollection。你正在考慮一個'ListView'。 – 2009-12-11 16:16:16

+0

錯誤'object'不包含'Selected'的定義 – Tony 2009-12-11 16:18:00

相關問題