心澄欲遣

不践迹,亦不入于室

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
#region 上移位置
/// <summary>
/// 上移方法
/// </summary>
/// <param name="listView"></param>
private void ListViewUpMove(ListView listView)
{
if (listView.SelectedItems.Count == 0)
{
return;
}

listView.BeginUpdate();
if (listView.SelectedItems[0].Index > 0)
{
foreach (ListViewItem lvi in listView.SelectedItems)
{
ListViewItem lviSelectedItem
= lvi;
int indexSelectedItem = lvi.Index;
listView.Items.RemoveAt(indexSelectedItem);
listView.Items.Insert(indexSelectedItem
- 1, lviSelectedItem);
}
}
listView.EndUpdate();

if (listView.Items.Count > 0 && listView.SelectedItems.Count > 0)
{
listView.Focus();
listView.SelectedItems[
0].Focused = true;
listView.SelectedItems[
0].EnsureVisible();
}
}
#endregion

#region 下移位置
/// <summary>
/// 下移方法
/// </summary>
/// <param name="listView"></param>
private void ListViewDownMove(ListView listView)
{
if (listView.SelectedItems.Count == 0)
{
return;
}

listView.BeginUpdate();
int indexMaxSelectedItem = listView.SelectedItems[listView.SelectedItems.Count - 1].Index;

if (indexMaxSelectedItem < listView.Items.Count - 1)
{
for (int i = listView.SelectedItems.Count - 1; i >= 0; i--)
{
ListViewItem lviSelectedItem
= listView.SelectedItems[i];
int indexSelectedItem = lviSelectedItem.Index;
listView.Items.RemoveAt(indexSelectedItem);
listView.Items.Insert(indexSelectedItem
+ 1, lviSelectedItem);
}
}
listView.EndUpdate();

if (listView.Items.Count > 0 && listView.SelectedItems.Count > 0)
{
listView.Focus();
listView.SelectedItems[listView.SelectedItems.Count
- 1].Focused = true;
listView.SelectedItems[listView.SelectedItems.Count
- 1].EnsureVisible();
}
}


#endregion
posted on 2011-04-28 14:59  心澄欲遣  阅读(1287)  评论(5编辑  收藏  举报
欢迎第myspace graphics个访客