Synthetic Ascension
Synthetic Ascension

Reputation: 319

Win32 C++ LVNI_PREVIOUS having no effect with ListView_GetNextItem()

I have a ListView where I need to perform operations on multiple selected rows. I start cycling through the selected rows using ListView_GetNextItem(hLV, -1, LVNI_SELECTED | LVNI_PREVIOUS). However when debugging, the index of the first selected row is returned, not the last. This is the same when only the LVNI_PREVIOUS flag is used.

The MS documentation states:

Windows Vista and later: Searches for an item that is ordered before the item specified in wParam. The LVNI_PREVIOUS flag is not directional (LVNI_ABOVE will find the item positioned above, while LVNI_PREVIOUS will find the item ordered before.) The LVNI_PREVIOUS flag basically reverses the logic of the search performed by the LVM_GETNEXTITEM or LVM_GETNEXTITEMINDEX messages.

Why would LVNI_PREVIOUS not work in the manner described? Could it be that I'm using the wrong commctrl version, as it does say Vista and above only?

Any help would be appreciated, thanks.

Upvotes: 2

Views: 239

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 597860

I did a test on Win10 and sure enough, even though the documentation does not say it, there IS a dependency on ComCtl32.dll v6.

WITHOUT ComCtl32.dll v6 enabled:

  • LVNI_PREVIOUS has no effect in LVM_GETNEXTITEM/ListView_GetNextItem().
  • LVM_GETNEXTITEMINDEX/ListView_GetNextItemIndex() do not work at all (the return value is always 0).

WITH ComCtl32.dll v6 enabled:

  • LVNI_PREVIOUS works in LVM_GETNEXTITEM/ListView_GetNextItem() as expected.
  • LVM_GETNEXTITEMINDEX/ListView_GetNextItemIndex() work, too.

So, make sure that ComCtl32.dll v6 is enabled properly (which you should do anyway, to get the best UI experience on Windows XP and later).

Upvotes: 1

Related Questions