Delphi - Get current index of selected item in TListView

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

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

+5
source share
2 answers

Use the ItemIndex property.

A value of -1 indicates no selection.

From the documentation:

Read ItemIndex to determine which item is selected. The first element in the list has index 0, the second element has index 1, etc. If no item is selected, the value of ItemIndex is -1. If a list control supports multiple selected items, ItemIndex is the index of the selected item with focus.

+8
source

Use the Index property of the Selected element

 if lvClients.Selected <> nil then index := lvClients.Selected.Index; 
+2
source

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


All Articles