How to code for checking item in wxDataViewListCtrl on its text selection?

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
buttonsrtoys
Knows some wx things
Knows some wx things
Posts: 45
Joined: Mon Jul 03, 2017 12:03 am

How to code for checking item in wxDataViewListCtrl on its text selection?

Post by buttonsrtoys » Fri Aug 03, 2018 5:01 pm

I have a wxDataViewListCtrl and want to code the behavior where a checkbox gets checked when its corresponding text is selected.

I have a handler that's called when the user selects the text of an item (on EVT_DATAVIEW_SELECTION_CHANGED) where I SetValue of the row to true. I also have a handler that's called when the checkbox is checked (on EVT_DATAVIEW_ITEM_VALUE_CHANGED) that then gets trigger by SetValue. Problem is, when the user checks a checkbox explicitly, my EVT_DATAVIEW_ITEM_VALUE_CHANGED handler is getting called twice--once when my EVT_DATAVIEW_SELECTION_CHANGED handler calls SetValue and then again through the normal wxWidgets event handler.

So, I'm thinking that after my EVT_DATAVIEW_SELECTION_CHANGED calls SetValue I need to purge the event queue of EVT_DATAVIEW_SELECTION_CHANGED? Is so, how is this done? If there's a cleaner way, I'm all ears.

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

Re: How to code for checking item in wxDataViewListCtrl on its text selection?

Post by ONEEYEMAN » Fri Aug 03, 2018 7:17 pm

Hi,
Which platform and wx version?
Can you show the code of both handlers?

You can try to set the flag in the item selection event and check it in the selection changed one.

Thank you.

buttonsrtoys
Knows some wx things
Knows some wx things
Posts: 45
Joined: Mon Jul 03, 2017 12:03 am

Re: How to code for checking item in wxDataViewListCtrl on its text selection?

Post by buttonsrtoys » Fri Aug 03, 2018 7:21 pm

Windows 10, Wx 3.1.1

I thought of setting/checking a flag but unfortunately when the checkbox is checked, the selection handler is called before the item-changed handler, so, unless I'm missing something, using a flag wouldn't work.

Post Reply