c# listview 删除选中子项

 //删除子项
        private void button2_Click(object sender, EventArgs e)
        {
            //判断它的值,如果没选中,是没有值的。
            //删除选中的子项listview.items[]
            //删除选中的子项,还是不成功
          //this.textBox1.Text=this.listView1.Items[this.listView1.SelectedIndices[0]].Text;
          //listView1.SelectedItems[listView1.Items[listView1.SelectedIndices[0]].Index].Remove();
          //MessageBox.Show("已成功删除子项" + this.textBox1.Text);

          ListView.SelectedIndexCollection sic = listView1.SelectedIndices;
          try
          {
              //int j = 0;
              foreach (int i in sic)
              {
                  //删除选中子项是成功,为何listview.selecteditems[index]就报错索引错误
                  //删除选中子项终于成功,代码是listview.items[i].text
                  //listview.items[i]提示的是listviewitem删除,而非listviewitem标签
                  //删除的提示消息框必须在removeat删除动作之前,因为删除后已删除的索引位置发生了变化

                 MessageBox.Show("已删除子项" + listView1.Items[i].Text);
                  listView1.Items.RemoveAt(i);
                  //j = j + 1;

                
                 
              }
          }
            catch(Exception ebs)
           {
               MessageBox.Show(ebs.Message);
           }
           
        }
       

请使用浏览器的分享功能分享到微信等