手机
当前位置:查字典教程网 >编程开发 >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选中项向上或向下移动的方法】相关文章:

SQL语句删除和添加外键、主键的方法

C# TrieTree介绍及实现方法

C# WinForm中Panel实现用鼠标操作滚动条的实例方法

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

用C#实现启动另一程序的方法实例

C# 如何在MVC3中取消备用控制器的选择

用C#缩小照片上传到各种空间的具体方法

c#启动EXE文件的方法实例

C#实现图片分割方法与代码

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

精品推荐
分类导航