Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi - Get current index of selected item in TListView

I have a TListView in a form and I would like to know the index of the selected item. I tried to find a method or a property of my TListView which gives that information but the only thing I found was lvClients.Selected and it doesn't give the index of this item.

How to get the index of the selected item in my TListView?

like image 693
Moussamoa Avatar asked Mar 24 '15 08:03

Moussamoa


Video Answer


2 Answers

Use the ItemIndex property.

A value of -1 indicates no selection.

From documentation:

Read ItemIndex to determine which item is selected. The first item in the list has index 0, the second item has index 1, and so on. If no item is selected, the value of ItemIndex is -1. If the list control supports multiple selected items, ItemIndex is the index of the selected item that has focus.

like image 138
LU RD Avatar answered Oct 02 '22 23:10

LU RD


Use Index property of Selected item

if lvClients.Selected <> nil then
  index := lvClients.Selected.Index;
like image 42
Dalija Prasnikar Avatar answered Oct 02 '22 22:10

Dalija Prasnikar