Author Topic: Combobox cannot capture the Enter command.  (Read 3436 times)

Offline cyuyan

  • Multiple posting newcomer
  • *
  • Posts: 21
Combobox cannot capture the Enter command.
« on: February 16, 2024, 02:01:41 pm »
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.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1574
Re: Combobox cannot capture the Enter command.
« Reply #1 on: February 16, 2024, 02:20:46 pm »
Quote
My program cannot run properly

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

Offline cyuyan

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: Combobox cannot capture the Enter command.
« Reply #2 on: February 16, 2024, 02:42:40 pm »
Looking at the picture below, I typed some letters and then pressed the Enter key, but the program didn't respond.

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1574
Re: Combobox cannot capture the Enter command.
« Reply #3 on: February 16, 2024, 02:51:29 pm »
Can you attach your current cpp file?

Offline cyuyan

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: Combobox cannot capture the Enter command.
« Reply #4 on: February 16, 2024, 02:55:35 pm »
Please see attach. Thank you!

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1574
Re: Combobox cannot capture the Enter command.
« Reply #5 on: February 16, 2024, 04:00:40 pm »
You have not checked wxTE_PROCESS_ENTER in the combobox style (I asked you explicitly about this):
Code
CmdBox = new wxComboBox(wxp1, ID_COMBOBOX1, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, 0, 0, wxDefaultValidator, _T("ID_COMBOBOX1"));
should be
Code
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;
Quote
You 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.
« Last Edit: February 16, 2024, 06:36:09 pm by Miguel Gimenez »

Offline cyuyan

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: Combobox cannot capture the Enter command.
« Reply #6 on: February 17, 2024, 07:27:38 am »
Thank you very much!