Code::Blocks Forums

User forums => General (but related to Code::Blocks) => Topic started by: cyuyan on February 16, 2024, 02:01:41 pm

Title: Combobox cannot capture the Enter command.
Post by: cyuyan 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.
Title: Re: Combobox cannot capture the Enter command.
Post by: Miguel Gimenez 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?
Title: Re: Combobox cannot capture the Enter command.
Post by: cyuyan 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.
Title: Re: Combobox cannot capture the Enter command.
Post by: Miguel Gimenez on February 16, 2024, 02:51:29 pm
Can you attach your current cpp file?
Title: Re: Combobox cannot capture the Enter command.
Post by: cyuyan on February 16, 2024, 02:55:35 pm
Please see attach. Thank you!
Title: Re: Combobox cannot capture the Enter command.
Post by: Miguel Gimenez 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 (https://wiki.codeblocks.org/index.php/WxSmith_tutorial:_Keyboard_Input_and_Displaying_Results#Getting_Input_from_the_User_and_Handling_the_Items_List_in_a_Combobox) 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.
Title: Re: Combobox cannot capture the Enter command.
Post by: cyuyan on February 17, 2024, 07:27:38 am
Thank you very much!