The almost abstract base class for grid tables.
A grid table is responsible for storing the grid data and, indirectly, grid cell attributes. The data can be stored in the way most convenient for the application but has to be provided in string form to wxGrid. It is also possible to provide cells values in other formats if appropriate, e.g. as numbers.
This base class is not quite abstract as it implements a trivial strategy for storing the attributes by forwarding it to wxGridCellAttrProvider and also provides stubs for some other functions. However it does have a number of pure virtual methods which must be implemented in the derived classes.
wxGrid by default only provides a basic spreadsheet-like widget. To extend it's functionality, you can provide a custom backend for providing data by creating a class that is derived from wxGridTableBase, and tell your wxGrid to use an instance of that.
Overriding the Pure Virtual Functions
These functions are defined as pure virtual in wxGridTableBase, so your derived class must override them:
virtual int GetNumberRows();
This function returns the number of rows the grid will have.
virtual int GetNumberCols();
Returns the number of columns the grid will have.
virtual bool IsEmptyCell( int row, int col );
Returns whether the data cell at the specified row and column is empty or not.
virtual wxString GetValue( int row, int col );
Override this function to provide a way for the grid to get read access to your data.
virtual void SetValue( int row, int col, const wxString& value );
Override this function to provide a way for the grid to get write access to your data.
The Fun Stuff :)
Now that that's done, we can change the way the data is described and presented in the grid.
For example, you can override GetRow/ColLabelValue to give custom labels to your grid, or you can even override SetRow/ColLabelValue too, to allow the application to change the label values during run-time.
Telling wxGrid to Use Your WxGridTableBase Derivative
Use YourWxGridInstance.SetTable(pointer to YourTableInstance) to make your wxGrid use your custom data table.
wxGrid* grid = new wxGrid(this, -1); wxGridTableBaseDerivative* table = new wxGridTableBaseDerivative(); grid->SetTable(table);