mercredi 29 juin 2022

function check from wxCheckListBox crash when it is called (wxwidgets)

I'm working on a application project for me with wxWidgets, and I encounter some troubles with the wxCheckListBox class. I am looking for a solution, and I saw that the check function worked well in the constructor function, but not in an event function. I have a check box "select all" who handle an event to select all check box of a list, here is my code

CheckListWindow::CheckListWindow(const wxString& name, const wxPoint& pos, const wxSize& size)
    : wxFrame(nullptr, wxID_ANY, name, pos, size)
{
    wxBoxSizer* m_sizer = new wxBoxSizer(wxHORIZONTAL);
    wxCheckListBox* m_checklist = new wxCheckListBox(this, wxID_ANY, wxPoint(20, 20), wxDefaultSize, g_vecPDF);

    wxCheckBox* m_selectall = new wxCheckBox(this, ID_CHECKBOX, wxString("Tout sélectionner"), wxPoint(10, wxDefaultPosition.y));
    m_checklist->Check(1, true); // work

    m_sizer->Add(m_selectall);
    m_sizer->Add(m_checklist);

    m_sizer->SetSizeHints(this);
}

void CheckListWindow::OnCheckBox(wxCommandEvent& evt)
{
    for (int index{ 0 }; index < static_cast<int>(g_vecPDF.size()); index++)
    {
        m_checklist->Check(index, true); // doesn't work
    }
    evt.Skip();
}

If I do that, the application crash when the event function is called. My question is, is there a way to modify the check box after his construction ?

Thank you!




Aucun commentaire:

Enregistrer un commentaire