Get next / previous item in ObjectListView

My application uses the Q and A keys to go to the next item in an ObjectListView, which works fine until the user sorts the list items using one of the column headers. If the user sorted, then pressing the Q / A keys causes the list to move through the list items, as it seems to use the original order rather than the current order.

So, I'm looking for a solution that allows the user to move to the next element even after the user is sorted. The code I currently have (for key A only) 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); } 
+6
source share
1 answer

This works correctly, for example. reduce the displayed items:

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

and to display the displayed items:

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

Source: https://habr.com/ru/post/943518/


All Articles