2009-12-11 41 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

相关问题