WxGrid
lastmod 2026-11-10created 2015-05-204 edits
wxGrid is a wxWidgets control that displays and edits a table of rows and columns like a spreadsheet. After setting the size with CreateGrid, contents and labels are handled with methods such as SetCellValue, SetColLabelValue, and AppendRows, and the editor and renderer can be changed per cell. For large data, it also supports connecting a virtual table by inheriting wxGridTableBase.
Example
SvmPanel::SvmPanel(wxWindow * parent
, wxWindowID id, wxPoint const & pos, wxSize const & size)
: wxPanel(parent, id, pos, size)
{
wxBoxSizer * sizer = new wxBoxSizer(wxVERTICAL);
int const kProportion = 1;
int const kBorder = wxSizerFlags::GetDefaultBorder();
grid = new wxGrid(this, ID_SVM_PANEL__GRID);
grid->CreateGrid(ROW, COLUMN);
grid->SetColLabelSize(COLUMN_LABEL_HEIGHT);
grid->SetRowLabelSize(ROW_LABEL_WIDTH);
grid->SetRowLabelAlignment(wxALIGN_RIGHT, wxALIGN_CENTRE);
grid->SetLabelFont(wxFont(FONT_SIZE, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD));
grid->SetColLabelValue(static_cast<int>(LabelIndex::FRAME), wxT("FRAME"));
grid->SetColLabelValue(static_cast<int>(LabelIndex::BLOCK_X), wxT("BX"));
grid->SetColLabelValue(static_cast<int>(LabelIndex::BLOCK_Y), wxT("BY"));
grid->SetColLabelValue(static_cast<int>(LabelIndex::LABEL), wxT("LABEL"));
grid->SetColLabelValue(static_cast<int>(LabelIndex::ENERGE2D), wxT("E2D"));
grid->SetColLabelValue(static_cast<int>(LabelIndex::ENERGE1D), wxT("E1D"));
grid->SetColLabelValue(static_cast<int>(LabelIndex::ENERGE_RED), wxT("RED"));
grid->SetColLabelValue(static_cast<int>(LabelIndex::ENERGE_GREEN), wxT("GREEN"));
grid->SetColLabelValue(static_cast<int>(LabelIndex::ENERGE_BLUE), wxT("BLUE"));
grid->SetColLabelValue(static_cast<int>(LabelIndex::ENERGE_NORM), wxT("NORM"));
int index = 0;
for (index = 0; index < COLUMN; ++index) {
grid->SetColSize(index, COLUMN_ITEM_WIDTH);
}
for (index = 0; index < ROW; ++index) {
grid->SetRowSize(index, ROW_ITEM_HEIGHT);
}
grid->AppendRows();
grid->SetCellValue(grid->GetNumberRows() - 1, 0, wxT("A"));
grid->SetCellValue(grid->GetNumberRows() - 1, 1, wxT("B"));
grid->AppendRows();
grid->SetCellValue(grid->GetNumberRows() - 1, 0, wxT("C"));
grid->SetCellValue(grid->GetNumberRows() - 1, 1, wxT("D"));
grid->AppendRows();
// InsertRows();
// InsertCols();
// AppendRows();
// AppendCols();
// DeleteRows();
// DeleteCols();
grid->ClearGrid(); // Clears all data in the underlying grid table and repaints the grid.
grid->DeleteRows(0, grid->GetNumberRows()); // Delete all rows;
sizer->Add(grid, kProportion, wxEXPAND | wxALL, kBorder);
SetSizer(sizer);
Center();
}