[wxMSW][3.1.3] How to Set a wxComboBox item data without getting the wxEVT_TEXT event to be sent? Topic is solved

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
tomay3000
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Mon Apr 24, 2017 4:23 am

[wxMSW][3.1.3] How to Set a wxComboBox item data without getting the wxEVT_TEXT event to be sent?

Post by tomay3000 »

Hello,
I have subclassed wxComboBox to create my own vesion "wxComboBoxEx" that filters the content when the combobox text changes.
The problem is that, when I call Set() on the combobox within wxEVT_TEXT handler, it sends the wxEVT_TEXT again and I found myself in a recursive loop.

I want to Set() a wxComboBox item data without getting the wxEVT_TEXT event to be sent again.

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

Re: [wxMSW][3.1.3] How to Set a wxComboBox item data without getting the wxEVT_TEXT event to be sent?

Post by doublemax »

virtual void wxComboBox::SetValue ( const wxString & text )
virtual

Sets the text for the combobox text field.

For normal, editable comboboxes with a text entry field calling this method will generate a wxEVT_TEXT event, consistently with wxTextEntry::SetValue() behaviour, use wxTextEntry::ChangeValue() if this is undesirable.
Use the source, Luke!
tomay3000
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Mon Apr 24, 2017 4:23 am

Re: [wxMSW][3.1.3] How to Set a wxComboBox item data without getting the wxEVT_TEXT event to be sent?

Post by tomay3000 »

When I said: Set(), I was talking about wxItemContainer::Set() not wxTextEntry::SetValue(), that is the item data "wxArrayString" of the list box associated with the combobox.

For some reason wxEVT_TEXT is sent if I call wxItemContainer::Set(), and I don't like that behaviour.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [wxMSW][3.1.3] How to Set a wxComboBox item data without getting the wxEVT_TEXT event to be sent?

Post by doublemax »

Sorry, i overlooked that.

I don't see an easy solution for that. I'd try UnBind()ing the wxEVT_TEXT handler temporarily.
Use the source, Luke!
tomay3000
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Mon Apr 24, 2017 4:23 am

Re: [wxMSW][3.1.3] How to Set a wxComboBox item data without getting the wxEVT_TEXT event to be sent?

Post by tomay3000 »

You solution gave me an idea:
May be I can do it like setting a bool member variable like bool m_bSetting to true before Set() and false after it, using the help of wxCriticalSectionLocker or wxMutexLocker and make an if (m_bSetting) check before I call Set().

I haven't tried it yet, but if it won't work, i will fall back to your solution.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: [wxMSW][3.1.3] How to Set a wxComboBox item data without getting the wxEVT_TEXT event to be sent?

Post by doublemax »

May be I can do it like setting a bool member variable like bool m_bSetting to true before Set() and false after it, using the help of wxCriticalSectionLocker or wxMutexLocker and make an if (m_bSetting) check before I call Set().
That should work, too. A mutex should not be necessary as there are no threads involved.
Use the source, Luke!
Post Reply