Page 1 of 1

Selecting Multiple Items In A wxListBox Without Having To Manually Press Ctrl

Posted: Mon Feb 11, 2019 11:07 pm
by Everydaydiesel
Hello,

I have a wxListBox and basically I want to be able to click items and if it is selected then deselect it and if it is deselected then it should be selected.

How can I do this without having to hold down the control key?

Thanks in advance!

Re: Selecting Multiple Items In A wxListBox Without Having To Manually Press Ctrl

Posted: Tue Feb 12, 2019 3:51 pm
by ONEEYEMAN
Hi,
RTFM - in here.

Thank you.

Re: Selecting Multiple Items In A wxListBox Without Having To Manually Press Ctrl

Posted: Tue Feb 12, 2019 4:57 pm
by Everydaydiesel
Thank you for the reply however that does not really help me.

I already have wxLB_MULTIPLE and I CAN hold the ctl key down and select multiple items. My question is, how can I create this functionality WITHOUT having to hold ctl.

Re: Selecting Multiple Items In A wxListBox Without Having To Manually Press Ctrl

Posted: Tue Feb 12, 2019 5:03 pm
by doublemax
I already have wxLB_MULTIPLE and I CAN hold the ctl key down and select multiple items. My question is, how can I create this functionality WITHOUT having to hold ctl.
Platform, wxWidgets version?

With wxLB_MULTIPLE you should get the behavior you want. I checked with the "widgets" sample under Windows. Did you maybe set both wxLB_MULTIPLE and wxLB_EXTENDED?

Re: Selecting Multiple Items In A wxListBox Without Having To Manually Press Ctrl

Posted: Tue Feb 12, 2019 5:06 pm
by PB
I believe that ONEEYEMAN meant that you may need to do this yourself, handling wxEVT_LISTBOX and de/selecting items based on their state and control keys pressed.

BTW, what about using wxCheckListBox instead: many users find selecting multiple items using <Ctrl> or <Shift> difficult, some may not even be aware that such a thing is possible...

Re: Selecting Multiple Items In A wxListBox Without Having To Manually Press Ctrl

Posted: Tue Feb 12, 2019 7:10 pm
by ONEEYEMAN
Hi,
@PB: There is no special handling is required to get the desired behaviour (at least when you are on Windows).
@OP: Check that you are not set an extended style for the control. Also see if you can reproduce this in the widgets sample.
And of course it would be nice to know the answers to doublemax' questions...

Thank you.

Re: Selecting Multiple Items In A wxListBox Without Having To Manually Press Ctrl

Posted: Tue Feb 12, 2019 9:13 pm
by PB
Oops, sorry I had no idea that this is supported out of the box.

Re: Selecting Multiple Items In A wxListBox Without Having To Manually Press Ctrl

Posted: Tue Feb 12, 2019 10:32 pm
by ONEEYEMAN
Hi, PB,
On Windows it is. In order to have a Ctrl+click behavior, you should set an extended style, which OP doesn't want.

But on GTK, things will be different. Setting wxLB_MULTIPLE will produce the behavior of wxLB_MULTIPLE + wxLB_EXTENDED, because GTK+ does not support multiple selection with just mouse clicks. So, on *nix it doesn't matter whether you set wxLB_EXTENDED or not - you will still get this behaviour as it is a native control.

OSX, however, behaves as MSW, I think (not at home and can't verify). You will get multiple selections with just clicks and you have to have wxLB_EXTENDED in order to get Ctrl+mouse clicks.

My guess would be that wxLB_EXTENDED style was created to have MSW/OSX behave the same as GTK+ although on MSW there is a style that supports this behaviour.

That's why it would be interesting to know what platform the OP is using (as you know most people doesn't read the docs ;-) )

Thank you.

Re: Selecting Multiple Items In A wxListBox Without Having To Manually Press Ctrl

Posted: Wed Feb 13, 2019 4:53 pm
by Everydaydiesel
doublemax wrote:
I already have wxLB_MULTIPLE and I CAN hold the ctl key down and select multiple items. My question is, how can I create this functionality WITHOUT having to hold ctl.
Platform, wxWidgets version?

With wxLB_MULTIPLE you should get the behavior you want. I checked with the "widgets" sample under Windows. Did you maybe set both wxLB_MULTIPLE and wxLB_EXTENDED?

Hello and thank you for the reply.

its on linux and wxwidgets 3.0

I tried to select wxLB_MULTIPLE and wxLB_EXTENDED but this did not work.

I want the functionality WITHOUT holding the ctrl key down. It works while holding ctl down. Is there any way to get this without having the user hold down ctrl?

Re: Selecting Multiple Items In A wxListBox Without Having To Manually Press Ctrl

Posted: Wed Feb 13, 2019 5:18 pm
by ONEEYEMAN
Hi,
The behaviour you want is not supported by GTK (underlying toolkit).

There is nothing that can be done about it unfortunately.

Thank you.

P.S.: You can try to use generic wxListBox to get the behaviour you want...

Re: Selecting Multiple Items In A wxListBox Without Having To Manually Press Ctrl

Posted: Wed Feb 13, 2019 5:32 pm
by doublemax
What you could try: Catch the "normal" wxEVT_LEFT_DOWN event, use wxListBox::HitTest to find the item under the mouse (if any), and then toggle its selection status yourself.

Re: Selecting Multiple Items In A wxListBox Without Having To Manually Press Ctrl

Posted: Wed Feb 13, 2019 8:24 pm
by New Pagodi
Would using a wxCheckListBox work.

Image