Firemonkey App, Windows and MacOS target.
I need to know what item is selected when a user scroll with the cursor keys or click with the mouse a listview item.
I can react to the mouse click via the onItemClick event, thats fine, also the onItemsChange event is fired when I move the selection with the cursor keys, but the selected property of the listview stays always at nil within that event.
Is this a bug or is there something I miss?
How do I know what item is selected when user use the cursor keys within the control?
You are using the wrong event. The OnItemsChange
event is an
Event that occurs after a list of items has been changed.
as the documentation states. Do you change the list of items? No, you don't.
What you are looking for is the OnChange
event:
Occurs when the ItemIndex property changes as a result of a user selecting a different item. Write an OnChange event handler to respond to changes of the ItemIndex property. OnChange allows a response once the list has been successfully changed.
See the documentation for more details.