手机
当前位置:查字典教程网 >编程开发 >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# DataGridView添加新行的2个方法

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

C# 批处理调用方法

c#中虚函数的相关使用方法

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

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

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

C#中将字符串转换为整型的三种解决方法总结

c#模拟平抛运动动画的方法详解

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

精品推荐
分类导航