Issue with SelectedItemIndex in TAdvSmoothImageListBox


Following my issues described here: AdvSmoothImageListBox issues with multi-selection, I've updated to the latest version but I still have a problem.

With the attached project, when I select the first item then the second one using ctrl-click the SelectedItemIndex property on the list returns 0 which is fine (check caption in the footer). But if I ctrl-click to unselect the first item, the property still returns 0 whereas the highlighted item in the list is the second one (index = 1). (25.2 KB)

The SelectedItemIndex returns the last item that was clicked, which in this case is the one you unselect.

As mentioned in the previous topic, you will need to use the OnMultiItemSelect event.

We have fixed the first issue and to handle your second request we have implemented the OnMultiItemSelect event, which will return the last item that was clicked and an array of all the selected items.

I am talking about the property SelectedItemIndex of the TAdvSmoothImageListBox, not the itemindex parameter of the OnItemSelect event nor the LastSelectedItemIndex parameter of the OnMultiItemSelect event.

If you try the sample you will see that the SelectedItemIndex value can be different that the item highlighted in the list.

SelectedItemIndex can be used for single selection, but this has another behavior for multi selection.
There it returns the last clicked item.

We will need to check if it is possible to change this as a lot of users might already use this implementation.

Therefor we've created the event OnMultiItemSelect as a start to use this to work with the index on multi-select.

I've updated the sample, and now I update the footer using the OnMultiItemSelect event, and I display the SelectedItemIndex in it.

When I click on the first item, SelectedItemIndex = 0, then I ctrl-click on the third item, SelectedItemIndex = 0. If I understand you, I should have SelectedItemIndex = 2 as the last clicked item is the third one?

And another question, when MultiSelect = true and without using the OnMultiItemSelect event,
the only way to know which item is selected is to go through all the items of the list and check their Selected property? (25.3 KB)

LastSelectedItemIndex returns the last clicked item as the SelectedItemIndex,
To check if your item is selected and to answer your second question, you have the selected items in the array: SelectedItems: TAdvSmoothImageListBoxItemArray.

This is the result I get when I click on the first item then the second:

For me the SelectedItemIndex correspond to the first clicked item and does not change if I ctrl-click on other items to select/unselect them. It will only change when I click on another item (without ctrl).

So the best thing to do is to never use SelectedItemIndex when multi-selection is activated.