Re: How to listen to multi-item selection with wxListCtrl

Vadim Zeitlin <[email protected]>
Newsgroups gmane.comp.lib.wxwindows.general
Message-ID <[email protected]>
On Mon, 28 Aug 2023 21:00:29 +0200 Andreas Falkenhahn wrote:

AF> the answer to this must be really obvious but for some reason I just
AF> don't see it.

 Unfortunately I have bad news: you are not really missing anything, it's a
well-known problem with wxListCtrl.

AF> When using a multi-selection wxListCtrl I can listen to
AF> EVT_LIST_ITEM_SELECTED to learn if an item is selected. However,
AF> EVT_LIST_ITEM_SELECTED is only sent in case a single new item is
AF> selected, either by clicking on it or by holding down CTRL and then
AF> clicking on an item to add it to the batch of currently selected items.

 Yes, and there is a long-standing (and this is not an exaggeration) bug
about it, see https://github.com/wxWidgets/wxWidgets/issues/4541 (there are
also #19180, #20979, #21284 which are/might be related).

AF> However, when holding down SHIFT and clicking on an item to select all
AF> items between the active and the clicked item I'm not getting
AF> EVT_LIST_ITEM_SELECTED at all. So how am I supposed to learn about the
AF> selection of multiple items using LMB+shift? Is there an event for this
AF> or does this need to be done the hard way by installing a generic LMB
AF> listener or something?

 Typically the UI doesn't need to change on every selection change in a
multi-select wxListCtrl, but if you do, you probably need to do it from
wxEVT_IDLE handler and examine the selection all the time. This is heavy
but should work reliably.

 Of course, fixing the bug would be welcome too, but considering that
nobody has stepped up to do it since 15+ years I don't have great hope for
this...

 Regards,
VZ

-- 
TT-Solutions: wxWidgets consultancy and technical support
              https://www.tt-solutions.com/
signature.asc (application/pgp-signature, 195 B)
-----BEGIN PGP SIGNATURE-----

iF0EABECAB0WIQQx+vLQdOwioQqkxtoG6kHeT2wehgUCZO0QlwAKCRAG6kHeT2we
hviAAKCa0D53PL6ugz0zIeNGHpHs732CxQCghTTokUq6PJr6oLEaZYVzyeblh9E=
=SSTw
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.