您的位置:首页 > 其它

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

2008-11-18 21:32 357 查看
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();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐