wxComboPopup open without focus

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
Rob'
Experienced Solver
Experienced Solver
Posts: 53
Joined: Mon Dec 08, 2008 10:10 pm

wxComboPopup open without focus

Post by Rob' » Mon Aug 16, 2010 6:44 pm

How can I open the wxComboPopup without focus?

What I want to accomplish is to open the wxComboPopup and to highlight the item in accordance to the text, when the user types a character into the TextCtrl. The TextCtrl keeps the focus and the user can now type more characters while the wxComboPopup remains open.


Thanks in advance
Rob'

eranif
Moderator
Moderator
Posts: 607
Joined: Tue Nov 29, 2005 7:10 pm
Location: Israel

Post by eranif » Mon Aug 16, 2010 9:17 pm

You can achieve it various ways, but the best way is to handle the OnFocus event (EVT_SET_FOCUS):

and call GetParent()->SetFocus() in it.

Code: Select all

	
void OnFocus(wxFocusEvent& event) {
	GetParent()->SetFocus();
	event.Skip();
}
Eran
IDE: CodeLite + wxCrafter
OS: All
https://wxcrafter.codelite.org
https://codelite.org

Rob'
Experienced Solver
Experienced Solver
Posts: 53
Joined: Mon Dec 08, 2008 10:10 pm

Post by Rob' » Tue Aug 17, 2010 7:18 pm

OnFocus of wich class?

I tried this:

Code: Select all

BEGIN_EVENT_TABLE(MyComboCtrl, wxComboCtrl)
    EVT_SET_FOCUS(MyComboCtrl::OnFocus)
    EVT_TEXT(wxID_ANY,MyComboCtrl::OnComboBoxUpdate)
END_EVENT_TABLE()

void OnFocus(wxFocusEvent& event)
  {
    ShowPopup(); // -> unknown software exception
    event.Skip();
  }

void OnComboBoxUpdate(wxCommandEvent& event )
  {
    if (!IsPopupShown()) ShowPopup();
    event.Skip();
  }
The OnComboBoxUpdate event handler opens the popup window as intended, but the TextCtrl loses the focus :( . Any ideas?

Thanks Rob'

Post Reply