LISTVIEW控件怎么删除末尾的一行,或删除中间选定的一行

来源:互联网 发布:javaweb源码 编辑:程序博客网 时间:2024/05/18 06:28

LISTVIEW控件怎么删除末尾的一行,或删除中间选定的一行
----------------------------
'选定一行
With lvw1
.ListItems.Remove (.SelectedItem.Index)
End With

listview1.Items.remove(listview1.selectedItems[0]);
item的方法items.remove(item);
参数是 项item

'尾行
With lvw1
.ListItems.Remove (.ListItems.Count)
End With

//////////////////////////////////////////////////////////////////////////////
 private void 删除itemToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0)
            {
                MessageBox.Show("没有");
            }
            else
            {
                string constr = "Data Source=EBCF5EA27E834E1;Initial    Catalog=MySchool;Integrated Security=True";
                SqlConnection connection = new SqlConnection(constr);
                string sql =string .Format( "delete from grade where    gradeid='{0}'",listView1.SelectedItems[0].SubItems[0].Text );
                SqlCommand command = new SqlCommand(sql, connection);
                connection.Open();
                int result = command.ExecuteNonQuery();
               
                if (result >0)
                {
                    MessageBox.Show("影响了");
     ///////////////////////////////////////////////////////////////
                    listView1.Items.Remove(listView1.SelectedItems[0]);
               ///////////////////////////////////////////////////////////////
                    //Form5_Load(sender, e);
                }
                connection.Close();
            }
        }

原创粉丝点击