Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
}
like image 220
user2198959 Avatar asked Apr 24 '13 09:04

user2198959


1 Answers

Right this seems to work e.g. 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);
like image 120
user2198959 Avatar answered Nov 03 '22 14:11

user2198959