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 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With