Delphi - Get current index of selected item in TListView

Moussamoa picture Moussamoa · Mar 24, 2015 · Viewed 13.4k times · Source

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.

Can someone help me to find how to get the index of the selected item in my TListView ? Thanks.

Answer

LU RD picture LU RD · Mar 24, 2015

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.