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();
}
}
----------------------------
'选定一行
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();
}
}
相关文章推荐
- 删除字符串开始及末尾的空白符,并且把数组中间的多个空格(如果有)符转化为1个
- hibernate中怎么只删除中间表
- 删除字符串开始及末尾的空白符,并且把数组中间的多个空格(如果有)符转化为1个。
- word怎么使用crtl+d删除一行
- js表格操作类(添加一行,删除一行,排序,上移选定行,下移选定行)
- poi中怎么像操作excel一样删除一行
- c程序设计语言_习题1-18_删除输入流中每一行末尾的空格和制表符,并删除完全是空格的行
- 删除选定的MSHFlexGrid控件中的一行
- 删除字符串开始及末尾的空白符,并且把数组中间的多个空格(如果有)符转化为1个。
- 删除字符串开始及末尾的空白符,并且把数组中间的多个空格(如果有)符转化为1个。
- 删除字符串开始及末尾的空格,并且把数组中间的多个空格转化为一个
- 删除选定的MSHFlexGrid控件中的一行
- word2003 当在一行文字中间插入文字时,后面的文字为何会自动删除?
- Java删除txt中文件中某一行数据 ,怎么实现?
- 字符串 删除字符串开始以及末尾的空白符,并把数组中间的多个空格(如果有)符转换为1个
- js操作表格操方法,增加,删除行,上移,下移一行选定行
- dataGridView删除(选定一行删除)
- 用jquery怎么删除<table>的一行
- 删除字符串开始及末尾的空白符,并且把数组中间的多个空格(如果有)符转化为1个
- 困惑好久 删除配置文件中的一行 怎么办?