How to temporarily disable an event handler

132 views
Skip to first unread message

Andreas Falkenhahn

unread,
Aug 29, 2023, 3:51:03 PM8/29/23
to wx-u...@googlegroups.com
I'm listening to wxEVT_LIST_ITEM_SELECTED for my wxListCtrl. That event also triggers when my app calls the Select() method to select an item. What is the typical way to prevent Select() from firing the event? Should I simply unbind and then bind again or how is this typically done? E.g. should I do something like this: (pseudo-code)

lv->Unbind(wxEVT_LIST_ITEM_SELECTED);
lv->Select(item);
lv->Bind(wxEVT_LIST_ITEM_SELECTED);

What's the recommended way to temporarily disable event handlers like wxEVT_LIST_ITEM_SELECTED?

--
Best regards,
Andreas Falkenhahn mailto:and...@falkenhahn.com

Igor Korot

unread,
Aug 29, 2023, 4:00:10 PM8/29/23
to wx-u...@googlegroups.com
Hi,

On Tue, Aug 29, 2023 at 2:51 PM Andreas Falkenhahn
<and...@falkenhahn.com> wrote:
>
> I'm listening to wxEVT_LIST_ITEM_SELECTED for my wxListCtrl. That event also triggers when my app calls the Select() method to select an item. What is the typical way to prevent Select() from firing the event? Should I simply unbind and then bind again or how is this typically done? E.g. should I do something like this: (pseudo-code)
>
> lv->Unbind(wxEVT_LIST_ITEM_SELECTED);
> lv->Select(item);
> lv->Bind(wxEVT_LIST_ITEM_SELECTED);

This should work just fine.
Do you have any issues with that?

Thank you.

>
> What's the recommended way to temporarily disable event handlers like wxEVT_LIST_ITEM_SELECTED?
>
> --
> Best regards,
> Andreas Falkenhahn mailto:and...@falkenhahn.com
>
> --
> Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
> ---
> You received this message because you are subscribed to the Google Groups "wx-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to wx-users+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/539402955.20230829215214%40falkenhahn.com.

Andreas Falkenhahn

unread,
Aug 29, 2023, 4:09:56 PM8/29/23
to Igor Korot
On 29.08.2023 at 21:59 Igor Korot wrote:

>> lv->Unbind(wxEVT_LIST_ITEM_SELECTED);
>> lv->Select(item);
>> lv->Bind(wxEVT_LIST_ITEM_SELECTED);

> This should work just fine.
> Do you have any issues with that?

No, I was just wondering whether this was the canonical way to do it or
if there was a better way because binding and unbinding sounds like this
could come with some overhead but maybe this isn't true.

PB

unread,
Aug 29, 2023, 4:21:47 PM8/29/23
to wx-users
Hi,

I have never used it so may be I am misunderstanding its purpose, but there is wxEventBlocker; so perhaps you could do something like (untested):
{
   wxEventBlocker blocker(lv, wxEVT_LIST_ITEM_SELECTED);
   lv->Select(item);
}

IMO, a bit cleaner than Bind/Unbind but as I said, I have no idea if it works.

PB


PB

unread,
Aug 29, 2023, 4:30:57 PM8/29/23
to wx-users
EDIT: Perhaps the window used in the blocker ctor should be the one where the event is handled, not the one generating the event...

Simon Richter

unread,
Aug 30, 2023, 2:49:39 AM8/30/23
to wx-u...@googlegroups.com
Hi,

On 8/30/23 04:52, Andreas Falkenhahn wrote:

> I'm listening to wxEVT_LIST_ITEM_SELECTED for my wxListCtrl. That event also triggers when my app calls the Select() method to select an item. What is the typical way to prevent Select() from firing the event?

That is a fairly uncommon requirement, so I'm suspecting a bit of an X-Y
problem here. What is the actual use case?

Simon
Reply all
Reply to author
Forward
0 new messages