Enter key does not activate default button when pressed in a wxListCtrl.

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
pkl
Knows some wx things
Knows some wx things
Posts: 36
Joined: Mon Jan 30, 2017 11:46 pm

Enter key does not activate default button when pressed in a wxListCtrl.

Post by pkl » Sun Jun 17, 2018 9:58 am

I believe this is about the last wxWidgets problem I have, but now is a good time with all those problems that have been solved for me.

I would like a wxListCtrl to ignore the "ENTER" key, so that pressing ENTER activates the default button.
I am aware of EVT_LIST_ITEM_ACTIVATED, but I wonder if there is some way to disable ENTER to specifically enable my desired functionality.

/Peter

User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Enter key does not activate default button when pressed in a wxListCtrl.

Post by eranon » Sun Jun 17, 2018 11:57 am

Hello,

Not sure, but worth to try: if you put your wxListCtrl and the default button on a wxPanel taking care that this panel hasn't the style wxWANTS_CHARS, the ENTER key should (or could since not tested) be directly adressed to the default button (not redirected to the list control).

Otherwise, if this doesn't work, effectively, you could trigger the default button yourself from your EVT_LIST_ITEM_ACTIVATED handler, taking care to implement a mechanism to differenciate double-click and ENTER key.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]

pkl
Knows some wx things
Knows some wx things
Posts: 36
Joined: Mon Jan 30, 2017 11:46 pm

Re: Enter key does not activate default button when pressed in a wxListCtrl.

Post by pkl » Mon Jun 18, 2018 7:22 pm

The panel does not have the wxWANTS_CHARS style so that is not the problem. I also thought about monitoring EVT_LIST_ITEM_ACTIVATED. Now where you also suggest this, it is probably the best solution, so I will pursue that path.
One thing I tried was to do was manually catch the ENTER key event and pass it on. For some weird reason, I could not make that work. Idid feel a bit spooky testing that solution - it is SOO hacky. But sometimes this is what you have to do.
Thank you for the input.

User avatar
eranon
Can't get richer than this
Can't get richer than this
Posts: 867
Joined: Sun May 13, 2012 11:42 pm
Location: France
Contact:

Re: Enter key does not activate default button when pressed in a wxListCtrl.

Post by eranon » Tue Jun 19, 2018 9:17 am

Hum, maybe you should take a look at the Dialogs sample, then "Dialogs > Test dialog default action". And see how it reacts on your platform (ie. if the OK command is well triggered on ENTER key when the list box has the focus). If it behaves as expected, you should compare your code and the sample's one. If this sample doesn't behave as expected, it's an issue about wxWidgets in your context.
[Ind. dev. - wxWidgets 3.0/3.1 under "Win 7 64-bit, TDM64-GCC" + "OS X 10.9, LLVM Clang"]

Post Reply