我要在winForm中实现移除ListBox选中的项,请大家指教一下!
最好是有代码指示,谢了!

解决方案 »

  1.   

    ListBox.Items.RemoveAt(ListBox.SelectedIndex);
      

  2.   

    支持楼上的。ListBox.Items.RemoveAt(ListBox.SelectedIndex);
      

  3.   

    this.listBox1.Items.Remove(this.listBox1.SelectedItem);
      

  4.   

    不行,报一个“在设置DataSource之后,不能删除items的错”
      

  5.   

    樓主是不是要點選刪除的阿
    private void listBox1_DoubleClick(object sender, System.EventArgs e)
    {
      int i=  listBox1.SelectedIndex;
              listBox1.Items.RemoveAt(i);
    }
    //同時要把你的DataSet內容一條一條ADD進去,不能用DATABIND邦定的
      

  6.   

    ListBox.Items.RemoveAt(ListBox.SelectedIndex);
      

  7.   

    我的代码,是这样的:
    System.Collections.ArrayList list=new ArrayList();
    string strString="";
    for(int i=0;i<cblIni.CheckedItems.Count;i++)
    {
       list.Add(this.cblIni.CheckedItems[i]);
    }
    this.listBox.DataSource=list;
    for(int i=0;i<this.listBox.SelectedItems.Count;i++)
    {
    this.listBox.Items.RemoveAt(this.listBox.SelectedIndex);就是这一行,报设置DataSource之后,不能再移除items项
     请大家指教一下
                   
    }
      

  8.   

    this.listBox.DataSource.RemoveAt(ListBox.SelectedIndex);
      

  9.   

    你这段代码写的我有种,datasouce除了问题,具体什么我也不知道,只能请高手回答了,如果你坚持,你可以这个改一下,System.Collections.ArrayList list=new ArrayList();
    string strString="";
    for(int i=0;i<cblIni.CheckedItems.Count;i++)
    {
       list.Add(this.cblIni.CheckedItems[i]);
    }
    this.listBox.DataSource=list;//就是这段foreach (object a in list)
                {
                    this.listBox.Items.Add(a);
                }
    for(int i=0;i<this.listBox.SelectedItems.Count;i++)
    {
    this.listBox.Items.RemoveAt(this.listBox.SelectedIndex);
      

  10.   

    Remove(selectItem)移除选定的行
    Removeat(selectItemIndex)移除号对应的行