News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Combobox cannot capture the Enter command.

Started by cyuyan, February 16, 2024, 02:01:41 PM

Previous topic - Next topic

cyuyan

Hello!

I'm using C::B 20.03 and wxWidgets 3.2.4. on Windows 10 (64 bit).
I have an example of wxsmith, see the link below.
https://wiki.codeblocks.org/index.php/WxSmith_tutorial:_Keyboard_Input_and_Displaying_Results

void Tutorial_9Frame::OnCmdBoxTextEnter(wxCommandEvent& event)
{
    wxString textFCB = CmdBox->GetValue();
    CmdBox->Insert(textFCB, 0);
    CmdBox->SetValue(wxT(""));
    if(CmdBox->GetCount() == 10)
        CmdBox->Delete(9);
    Results->AppendText(textFCB);
    Results->AppendText(_("\n"));

    strncpy(inbuf, (const char*) textFCB.mb_str(wxConvUTF8), 239);
    // anything(); //We will be using this later.
}
The above code captures the ENTER event, but my program cannot run properly.

Miguel Gimenez

QuoteMy program cannot run properly

Please clarify what are you expecting and what is happening. Did you check wxTE_PROCESS_ENTER?

cyuyan

Looking at the picture below, I typed some letters and then pressed the Enter key, but the program didn't respond.

Miguel Gimenez


cyuyan


Miguel Gimenez

#5
You have not checked wxTE_PROCESS_ENTER in the combobox style (I asked you explicitly about this):
CmdBox = new wxComboBox(wxp1, ID_COMBOBOX1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_COMBOBOX1"));
should be
CmdBox = new wxComboBox(wxp1, ID_COMBOBOX1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, 0, wxTE_PROCESS_ENTER, wxDefaultValidator, _T("ID_COMBOBOX1"));

Goto wxSmith and check it.

EDIT: extract fom the tutorial you were following;
QuoteYou may notice that nothing happens when you press Enter in CmdBox. That is because we have to set CmdBox to handle that event. Select this control in Code::Blocks Resources window, then in Properties open Style section and check wxTE_PROCESS_ENTER. Now it's working as expected.

cyuyan