wxGrid is a class for displaying and editing tabular information.
On each platform, the implementation has a different class name: on Motif, it is wxMotifGrid, and on Windows, the generic implementation wxGenericGrid is used. The wxGrid class is derived from a suitable platform-specific (or generic) implementation.
This separation of portable and platform-specific class names allows the programmer to use different grid implementations in the same program. For example, say the wxGenericGrid implementation is good at displaying lists without divisions, such as seen in the Windows 95 print manager window. But the wxMotifGrid implementation is better at displaying 1000 by 1000 grids, under Motif. In this case the programmer might choose to use both classes in the same program, thus 'optimizing' the Motif version of the application. (The example assumes that wxGenericGrid has been tested under Motif, which currently it has not).
To use wxGrid, include the wxgrid.h header file and link with the wxGrid library. Create a wxGrid object, or, if you need to override some default behaviour, create an object of a class derived from wxGrid. You need to call CreateGrid before there are any cells in the grid.
All row and column positions start from zero, and dimensions are in pixels.
If you make changes to row or column dimensions, call UpdateDimensions and then AdjustScrollbars. If you make changes to the grid appearance (such as a change of cell background colour or font), call Refresh for the changes to be shown.
The following fragment is taken from the file test.cc. Note the call to UpdateDimensions, which is required if the application has changed any dimensions such as column width or row height. You may also need to call AdjustScrollbars. In this case, AdjustScrollbars isn't necessary because it will be called by wxGrid::OnSize which is invoked when the window is first displayed.
// Make a grid frame->grid = new wxGrid(frame, 0, 0, 400, 400); frame->grid->CreateGrid(10, 8); frame->grid->SetColumnWidth(3, 200); frame->grid->SetRowHeight(4, 45); frame->grid->SetCellValue("First cell", 0, 0); frame->grid->SetCellValue("Another cell", 1, 1); frame->grid->SetCellValue("Yet another cell", 2, 2); frame->grid->SetCellTextFont(wxTheFontList->FindOrCreateFont(12, wxROMAN, wxITALIC, wxNORMAL), 0, 0); frame->grid->SetCellTextColour(*wxRED, 1, 1); frame->grid->SetCellBackgroundColour(*wxCYAN, 2, 2); frame->grid->UpdateDimensions();