I'm writing an application using wxGrid inside a notebook in a frame, the code is like this:
Code: Select all
#include <wx/wx.h>
#include <wx/grid.h>
#include <wx/notebook.h>
class MyFrame : public wxFrame
{
public:
MyFrame(wxWindow* parent = nullptr) : wxFrame(parent, wxID_ANY, "Test")
{
wxNotebook* notebook = new wxNotebook(this, wxID_ANY);
wxPanel* page = new wxPanel(notebook);
wxGrid* grid = new wxGrid(page, wxID_ANY);
grid_ = grid;
grid->CreateGrid(50, 50);
notebook->AddPage(page, wxString::Format("Page 1"), true);
page->Bind(wxEVT_SIZE, [page, grid](wxSizeEvent& e)
{
grid->SetSize(page->GetClientSize());
e.Skip();
});
page->Bind(wxEVT_GRID_CELL_RIGHT_CLICK, [grid, this](wxGridEvent& event)
{
wxMenu popup_menu;
popup_menu.SetTitle("Popup Menu");
popup_menu.AppendSeparator();
const int rc = GetPopupMenuSelectionFromUser(popup_menu, ScreenToClient(event.GetPosition()));
event.Skip();
});
}
private:
wxGrid* grid_;
};
class MyApp : public wxApp
{
public:
bool OnInit() override
{
(new MyFrame())->Show();
return true;
}
}; wxIMPLEMENT_APP(MyApp);
Thanks in advance.