#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