Page 1 of 1

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

Posted: Sun Aug 18, 2019 9:46 am
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.

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

Posted: Sun Aug 18, 2019 9:49 am
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.

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

Posted: Sun Aug 18, 2019 9:58 am
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.

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

Posted: Sun Aug 18, 2019 12:01 pm
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.

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

Posted: Sun Aug 18, 2019 12:43 pm
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.

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

Posted: Sun Aug 18, 2019 1:01 pm
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.