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

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Everydaydiesel
Experienced Solver
Experienced Solver
Posts: 98
Joined: Wed Oct 28, 2015 9:48 pm

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

Post by Everydaydiesel » Mon Feb 11, 2019 11:07 pm

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!

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 2928
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

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

Post by ONEEYEMAN » Tue Feb 12, 2019 3:51 pm

Hi,
RTFM - in here.

Thank you.

Everydaydiesel
Experienced Solver
Experienced Solver
Posts: 98
Joined: Wed Oct 28, 2015 9:48 pm

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

Post by Everydaydiesel » Tue Feb 12, 2019 4:57 pm

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.

User avatar
doublemax
Moderator
Moderator
Posts: 12986
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post by doublemax » Tue Feb 12, 2019 5:03 pm

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?
Use the source, Luke!

PB
Part Of The Furniture
Part Of The Furniture
Posts: 1833
Joined: Sun Jan 03, 2010 5:45 pm

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

Post by PB » Tue Feb 12, 2019 5:06 pm

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...

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 2928
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

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

Post by ONEEYEMAN » Tue Feb 12, 2019 7:10 pm

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.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 1833
Joined: Sun Jan 03, 2010 5:45 pm

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

Post by PB » Tue Feb 12, 2019 9:13 pm

Oops, sorry I had no idea that this is supported out of the box.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 2928
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

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

Post by ONEEYEMAN » Tue Feb 12, 2019 10:32 pm

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.

Everydaydiesel
Experienced Solver
Experienced Solver
Posts: 98
Joined: Wed Oct 28, 2015 9:48 pm

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

Post by Everydaydiesel » Wed Feb 13, 2019 4:53 pm

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?

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 2928
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

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

Post by ONEEYEMAN » Wed Feb 13, 2019 5:18 pm

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...

User avatar
doublemax
Moderator
Moderator
Posts: 12986
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

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

Post by doublemax » Wed Feb 13, 2019 5:32 pm

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.
Use the source, Luke!

New Pagodi
Super wx Problem Solver
Super wx Problem Solver
Posts: 269
Joined: Tue Jun 20, 2006 6:47 pm
Contact:

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

Post by New Pagodi » Wed Feb 13, 2019 8:24 pm

Would using a wxCheckListBox work.

Image

Post Reply