手机
当前位置:查字典教程网 >编程开发 >C#教程 >C#实现ListView选中项向上或向下移动的方法
C#实现ListView选中项向上或向下移动的方法
摘要:本文实例讲述了C#实现ListView选中项向上或向下移动的方法。分享给大家供大家参考。具体实现方法如下:privatevoidbutton...

本文实例讲述了C#实现ListView选中项向上或向下移动的方法。分享给大家供大家参考。具体实现方法如下:

private void buttonUp_Click(object sender, EventArgs e) { if (listView.SelectedItems.Count > 0 && listView.SelectedItems[0].Index != 0) { listView.BeginUpdate(); foreach (ListViewItem lvi in listView.SelectedItems) { ListViewItem item = lvi; int index = lvi.Index; listView.Items.RemoveAt(index); listView.Items.Insert(index - 1, item); } listView.EndUpdate(); } listView.Focus(); } private void buttonDown_Click(object sender, EventArgs e) { if (listView.SelectedItems.Count > 0 && listView.SelectedItems[listView.SelectedItems.Count - 1].Index < (listView.Items.Count-1)) { listView.BeginUpdate(); int count = listView.SelectedItems.Count; foreach (ListViewItem lvi in listView.SelectedItems) { ListViewItem item = lvi; int index = lvi.Index; listView.Items.RemoveAt(index); listView.Items.Insert(index + count, item); } listView.EndUpdate(); } listView.Focus(); }

希望本文所述对大家的C#程序设计有所帮助。

【C#实现ListView选中项向上或向下移动的方法】相关文章:

C#中将ListView中数据导出到Excel的实例方法

C# DataGridView添加新行的2个方法

C#访问PostGreSQL数据库的方法

C# 向二进制文件进行读写的操作方法

C#中隐式运行CMD命令行窗口的方法

C#实现对AES加密和解密的方法

C# DropDownList中点击打开新窗口的方法

用C#编写获取远程IP,MAC的方法

获得.net控件的windows句柄的方法

c# 获取数据库中所有表名称的方法

精品推荐
分类导航