Reputation: 17
am using delphi 10.1 with standard Tlistview vcl
ill try and exmple is better but am not very good at that sorry ok say I have the standard listview
has items in it in following order
now I have two buttons back and forward when I press the forward button it will get the first Item in the list Ken White and if i keep pressing the button it will go down the list till it gets to simon or the last entry.
now its the same for the back button but it would be in reverse were it go from bottom to top till it gos back to Ken White.
Sorry if it don't make much sense spelling not my things chaps sorry am dyslexic
Upvotes: 0
Views: 1423
Reputation: 54832
To move forward in a TListView
you can use GetNextItem
.
ListView1.Selected := ListView1.GetNextItem(ListView1.Selected, sdAll, []);
In the above, 'sdAll' specifies that the next item will be the one with its index one higher of the already selected item. This method selects the first item when there is no selected item. When the last item is already selected, it will be unselected after the call returns.
To go in the reverse direction, you can pass 'sdLeft' or 'sdAbove' instead of 'sdAll' if it is appropriate. If not, since there's no 'GetPreviousItem', you have to write code that would select the item with its index one lower than the already selected item. Example:
if not Assigned(ListView1.Selected) then
ListView1.Selected := ListView1.Items[ListView1.GetCount - 1]
else if ListView1.Selected.Index = 0 then
ListView1.Selected := nil
else
ListView1.Selected := ListView1.Items[ListView1.Selected.Index - 1];
You may have to modify the code if you want different behavior, for instance when the last item is selected and you press forward you want nothing to happen.
Upvotes: 1