Пример:
Code: Select all
#include <wx/wx.h>
#include <wx/aui/auibook.h>
#include <wx/grid.h>
class MyFrame : public wxFrame
{
public:
MyFrame() : wxFrame(NULL, wxID_ANY, "Test", wxDefaultPosition, wxSize(800, 600))
{
wxBoxSizer* topSizer;
topSizer = new wxBoxSizer(wxVERTICAL);
m_auinotebook = new wxAuiNotebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxAUI_NB_DEFAULT_STYLE);
topSizer->Add(m_auinotebook, 1, wxEXPAND | wxALL, 5);
m_grid = new wxGrid(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
m_grid->CreateGrid(0, 1);
m_grid->SetColLabelValue(0, "Значение");
m_auinotebook->AddPage(m_grid, "Грид");
wxBoxSizer* bSizer1 = new wxBoxSizer(wxHORIZONTAL);
m_Hint = new wxStaticText(this, wxID_ANY, wxT("Введите значение:"), wxDefaultPosition, wxDefaultSize, 0);
bSizer1->Add(m_Hint, 0, wxALL | wxALIGN_CENTER_VERTICAL, 5);
m_Value = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0);
bSizer1->Add(m_Value, 0, wxALL | wxEXPAND, 5);
bSizer1->Add(0, 0, 1, wxEXPAND, 5);
m_Add = new wxButton(this, wxID_ANY, wxT("Добавить"), wxDefaultPosition, wxDefaultSize, 0);
bSizer1->Add(m_Add, 0, wxALL, 5);
topSizer->Add(bSizer1, 0, wxEXPAND, 5);
this->SetSizer(topSizer);
this->Layout();
this->Centre(wxBOTH);
m_Add->Bind(wxEVT_BUTTON, [&](wxCommandEvent&)
{
auto value = m_Value->GetValue();
if (!value.empty())
{
m_grid->AppendRows();
m_grid->SetCellValue(m_grid->GetNumberRows() - 1, 0, value);
this->Layout();
}
});
}
protected:
wxAuiNotebook* m_auinotebook;
wxGrid* m_grid;
wxStaticText* m_Hint;
wxTextCtrl* m_Value;
wxButton* m_Add;
};
class MyApp : public wxApp
{
public:
bool OnInit()
{
(new MyFrame())->Show();
return true;
}
}; wxIMPLEMENT_APP(MyApp);
С GetPage я ошибся, не заметил, что это константный метод.