Get next/previous item in an ObjectListView

My application uses the Q and A keys to move to the next item in an ObjectListView, which works great as long as the user doesn't sort the list items using one of the column headers. If the user has sorted, then pressing the Q/A keys causes the list to jump around the list items, as it seems to use the original order, rather than the current order.

So I am looking for a solution that allows the user to move to the next item even after the user has sorted. The code I currently have (just for the A key) is below:

if (e.KeyCode == Keys.A)
{
  OLVListItem next = listSession.GetNextItem(listSession.SelectedItem);
  if (next == null)
  {
    return;
  }

  listSession.SelectedObject = (Session)next.RowObject;
  listSession.EnsureModelVisible((Session)next.RowObject);
}

Right this seems to work eg go down the displayed items:

int index = listSession.GetDisplayOrderOfItemIndex(listSession.SelectedItem.Index);
OLVListItem next = listSession.GetNthItemInDisplayOrder(index + 1);

and to go up the displayed items:

int index = listSession.GetDisplayOrderOfItemIndex(listSession.SelectedItem.Index);
OLVListItem next = listSession.GetNthItemInDisplayOrder(index - 1);
链接地址: http://www.djcxy.com/p/71202.html

上一篇: 创建精灵时,无法在等轴拼贴地图中找出正确的顶点

下一篇: 获取ObjectListView中的下一个/上一个项目