wxGrid and its related classes are used for displaying and editing tabular data. They provide a rich set of features for display, editing, and interacting with a variety of data sources. For simple applications, and to help you get started, wxGrid is the only class you need to refer to directly. It will set up default instances of the other classes and manage them for you. For more complex applications you can derive your own classes for custom grid views, grid data tables, cell editors and renderers. The wxGrid classes overview has examples of simple and more complex applications, explains the relationship between the various grid classes and has a summary of the keyboard shortcuts and mouse functions provided by wxGrid.
wxGrid has been greatly expanded and redesigned for wxWidgets 2.2 onwards. If you have been using the old wxGrid class you will probably want to have a look at the wxGrid classes overview to see how things have changed. The new grid classes are reasonably backward-compatible but there are some exceptions. There are also easier ways of doing many things compared to the previous implementation.
Derived from
wxScrolledWindow
wxWindow
wxEvtHandler
wxObject
Include files
<wx/grid.h>
Window styles
There are presently no specific window styles for wxGrid.
Event handling
The event handler for the following functions takes a wxGridEvent parameter. The ..._CMD_... variants also take a window identifier.
EVT_GRID_CELL_LEFT_CLICK(func) | The user clicked a cell with the left mouse button. Processes a wxEVT_GRID_CELL_LEFT_CLICK. |
EVT_GRID_CELL_RIGHT_CLICK(func) | The user clicked a cell with the right mouse button. Processes a wxEVT_GRID_CELL_RIGHT_CLICK. |
EVT_GRID_CELL_LEFT_DCLICK(func) | The user double-clicked a cell with the left mouse button. Processes a wxEVT_GRID_CELL_LEFT_DCLICK. |
EVT_GRID_CELL_RIGHT_DCLICK(func) | The user double-clicked a cell with the right mouse button. Processes a wxEVT_GRID_CELL_RIGHT_DCLICK. |
EVT_GRID_LABEL_LEFT_CLICK(func) | The user clicked a label with the left mouse button. Processes a wxEVT_GRID_LABEL_LEFT_CLICK. |
EVT_GRID_LABEL_RIGHT_CLICK(func) | The user clicked a label with the right mouse button. Processes a wxEVT_GRID_LABEL_RIGHT_CLICK. |
EVT_GRID_LABEL_LEFT_DCLICK(func) | The user double-clicked a label with the left mouse button. Processes a wxEVT_GRID_LABEL_LEFT_DCLICK. |
EVT_GRID_LABEL_RIGHT_DCLICK(func) | The user double-clicked a label with the right mouse button. Processes a wxEVT_GRID_LABEL_RIGHT_DCLICK. |
EVT_GRID_CELL_CHANGE(func) | The user changed the data in a cell. Processes a wxEVT_GRID_CELL_CHANGE. |
EVT_GRID_SELECT_CELL(func) | The user moved to, and selected a cell. Processes a wxEVT_GRID_SELECT_CELL. |
EVT_GRID_EDITOR_HIDDEN(func) | The editor for a cell was hidden. Processes a wxEVT_GRID_EDITOR_HIDDEN. |
EVT_GRID_EDITOR_SHOWN(func) | The editor for a cell was shown. Processes a wxEVT_GRID_EDITOR_SHOWN. |
EVT_GRID_CMD_CELL_LEFT_CLICK(id, func) | The user clicked a cell with the left mouse button; variant taking a window identifier. Processes a wxEVT_GRID_CELL_LEFT_CLICK. |
EVT_GRID_CMD_CELL_RIGHT_CLICK(id, func) | The user clicked a cell with the right mouse button; variant taking a window identifier. Processes a wxEVT_GRID_CELL_RIGHT_CLICK. |
EVT_GRID_CMD_CELL_LEFT_DCLICK(id, func) | The user double-clicked a cell with the left mouse button; variant taking a window identifier. Processes a wxEVT_GRID_CELL_LEFT_DCLICK. |
EVT_GRID_CMD_CELL_RIGHT_DCLICK(id, func) | The user double-clicked a cell with the right mouse button; variant taking a window identifier. Processes a wxEVT_GRID_CELL_RIGHT_DCLICK. |
EVT_GRID_CMD_LABEL_LEFT_CLICK(id, func) | The user clicked a label with the left mouse button; variant taking a window identifier. Processes a wxEVT_GRID_LABEL_LEFT_CLICK. |
EVT_GRID_CMD_LABEL_RIGHT_CLICK(id, func) | The user clicked a label with the right mouse button; variant taking a window identifier. Processes a wxEVT_GRID_LABEL_RIGHT_CLICK. |
EVT_GRID_CMD_LABEL_LEFT_DCLICK(id, func) | The user double-clicked a label with the left mouse button; variant taking a window identifier. Processes a wxEVT_GRID_LABEL_LEFT_DCLICK. |
EVT_GRID_CMD_LABEL_RIGHT_DCLICK(id, func) | The user double-clicked a label with the right mouse button; variant taking a window identifier. Processes a wxEVT_GRID_LABEL_RIGHT_DCLICK. |
EVT_GRID_CMD_CELL_CHANGE(id, func) | The user changed the data in a cell; variant taking a window identifier. Processes a wxEVT_GRID_CELL_CHANGE. |
EVT_GRID_CMD_SELECT_CELL(id, func) | The user moved to, and selected a cell; variant taking a window identifier. Processes a wxEVT_GRID_SELECT_CELL. |
EVT_GRID_CMD_EDITOR_HIDDEN(id, func) | The editor for a cell was hidden; variant taking a window identifier. Processes a wxEVT_GRID_EDITOR_HIDDEN. |
EVT_GRID_CMD_EDITOR_SHOWN(id, func) | The editor for a cell was shown; variant taking a window identifier. Processes a wxEVT_GRID_EDITOR_SHOWN. |
EVT_GRID_COL_SIZE(func) | The user resized a column by dragging it. Processes a wxEVT_GRID_COL_SIZE. |
EVT_GRID_ROW_SIZE(func) | The user resized a row by dragging it. Processes a wxEVT_GRID_ROW_SIZE. |
EVT_GRID_CMD_COL_SIZE(func) | The user resized a column by dragging it; variant taking a window identifier. Processes a wxEVT_GRID_COL_SIZE. |
EVT_GRID_CMD_ROW_SIZE(func) | The user resized a row by dragging it; variant taking a window identifier. Processes a wxEVT_GRID_ROW_SIZE. |
EVT_GRID_RANGE_SELECT(func) | The user selected a group of contiguous cells. Processes a wxEVT_GRID_RANGE_SELECT. |
EVT_GRID_CMD_RANGE_SELECT(id, func) | The user selected a group of contiguous cells; variant taking a window identifier. Processes a wxEVT_GRID_RANGE_SELECT. |
EVT_GRID_EDITOR_CREATED(func) | The editor for a cell was created. Processes a wxEVT_GRID_EDITOR_CREATED. |
EVT_GRID_CMD_EDITOR_CREATED(id, func) | The editor for a cell was created; variant taking a window identifier. Processes a wxEVT_GRID_EDITOR_CREATED. |
Function groups
Constructors and initialization
Display format
Selection functions
wxGrid::wxGrid
wxGrid::~wxGrid
wxGrid::AppendCols
wxGrid::AppendRows
wxGrid::AutoSize
wxGrid::AutoSizeColOrRow
wxGrid::AutoSizeColumn
wxGrid::AutoSizeColumns
wxGrid::AutoSizeRow
wxGrid::AutoSizeRows
wxGrid::BeginBatch
wxGrid::BlockToDeviceRect
wxGrid::CanDragColMove
wxGrid::CanDragColSize
wxGrid::CanDragRowSize
wxGrid::CanDragGridSize
wxGrid::CanEnableCellControl
wxGrid::CanHaveAttributes
wxGrid::CellToRect
wxGrid::ClearGrid
wxGrid::ClearSelection
wxGrid::CreateGrid
wxGrid::DeleteCols
wxGrid::DeleteRows
wxGrid::DisableCellEditControl
wxGrid::DisableDragColMove
wxGrid::DisableDragColSize
wxGrid::DisableDragGridSize
wxGrid::DisableDragRowSize
wxGrid::EnableCellEditControl
wxGrid::EnableDragColSize
wxGrid::EnableDragColMove
wxGrid::EnableDragGridSize
wxGrid::EnableDragRowSize
wxGrid::EnableEditing
wxGrid::EnableGridLines
wxGrid::EndBatch
wxGrid::Fit
wxGrid::ForceRefresh
wxGrid::GetBatchCount
wxGrid::GetCellAlignment
wxGrid::GetCellBackgroundColour
wxGrid::GetCellEditor
wxGrid::GetCellFont
wxGrid::GetCellRenderer
wxGrid::GetCellTextColour
wxGrid::GetCellValue
wxGrid::GetColAt
wxGrid::GetColLeft
wxGrid::GetColLabelAlignment
wxGrid::GetColLabelSize
wxGrid::GetColLabelValue
wxGrid::GetColMinimalAcceptableWidth
wxGrid::GetColMinimalWidth
wxGrid::GetColPos
wxGrid::GetColRight
wxGrid::GetColSize
wxGrid::GetDefaultCellAlignment
wxGrid::GetDefaultCellBackgroundColour
wxGrid::GetDefaultCellFont
wxGrid::GetDefaultCellTextColour
wxGrid::GetDefaultColLabelSize
wxGrid::GetDefaultColSize
wxGrid::GetDefaultEditor
wxGrid::GetDefaultEditorForCell
wxGrid::GetDefaultEditorForType
wxGrid::GetDefaultRenderer
wxGrid::GetDefaultRendererForCell
wxGrid::GetDefaultRendererForType
wxGrid::GetDefaultRowLabelSize
wxGrid::GetDefaultRowSize
wxGrid::GetGridCursorCol
wxGrid::GetGridCursorRow
wxGrid::GetGridLineColour
wxGrid::GetDefaultGridLinePen
wxGrid::GetRowGridLinePen
wxGrid::GetColGridLinePen
wxGrid::GridLinesEnabled
wxGrid::GetLabelBackgroundColour
wxGrid::GetLabelFont
wxGrid::GetLabelTextColour
wxGrid::GetNumberCols
wxGrid::GetNumberRows
wxGrid::GetOrCreateCellAttr
wxGrid::GetRowMinimalAcceptableHeight
wxGrid::GetRowMinimalHeight
wxGrid::GetRowLabelAlignment
wxGrid::GetRowLabelSize
wxGrid::GetRowLabelValue
wxGrid::GetRowSize
wxGrid::GetScrollLineX
wxGrid::GetScrollLineY
wxGrid::GetSelectionMode
wxGrid::GetSelectedCells
wxGrid::GetSelectedCols
wxGrid::GetSelectedRows
wxGrid::GetSelectionBackground
wxGrid::GetSelectionBlockTopLeft
wxGrid::GetSelectionBlockBottomRight
wxGrid::GetSelectionForeground
wxGrid::GetTable
wxGrid::GetViewWidth
wxGrid::HideCellEditControl
wxGrid::InitColWidths
wxGrid::InitRowHeights
wxGrid::InsertCols
wxGrid::InsertRows
wxGrid::IsCellEditControlEnabled
wxGrid::IsCurrentCellReadOnly
wxGrid::IsEditable
wxGrid::IsInSelection
wxGrid::IsReadOnly
wxGrid::IsSelection
wxGrid::IsVisible
wxGrid::MakeCellVisible
wxGrid::MoveCursorDown
wxGrid::MoveCursorLeft
wxGrid::MoveCursorRight
wxGrid::MoveCursorUp
wxGrid::MoveCursorDownBlock
wxGrid::MoveCursorLeftBlock
wxGrid::MoveCursorRightBlock
wxGrid::MoveCursorUpBlock
wxGrid::MovePageDown
wxGrid::MovePageUp
wxGrid::RegisterDataType
wxGrid::SaveEditControlValue
wxGrid::SelectAll
wxGrid::SelectBlock
wxGrid::SelectCol
wxGrid::SelectionToDeviceRect
wxGrid::SelectRow
wxGrid::SetCellAlignment
wxGrid::SetCellBackgroundColour
wxGrid::SetCellEditor
wxGrid::SetCellFont
wxGrid::SetCellRenderer
wxGrid::SetCellTextColour
wxGrid::SetCellValue
wxGrid::SetColAttr
wxGrid::SetColFormatBool
wxGrid::SetColFormatNumber
wxGrid::SetColFormatFloat
wxGrid::SetColFormatCustom
wxGrid::SetColLabelAlignment
wxGrid::SetColLabelSize
wxGrid::SetColLabelValue
wxGrid::SetColMinimalWidth
wxGrid::SetColMinimalAcceptableWidth
wxGrid::SetColPos
wxGrid::SetColSize
wxGrid::SetDefaultCellAlignment
wxGrid::SetDefaultCellBackgroundColour
wxGrid::SetDefaultCellFont
wxGrid::SetDefaultCellTextColour
wxGrid::SetDefaultEditor
wxGrid::SetDefaultRenderer
wxGrid::SetDefaultColSize
wxGrid::SetDefaultRowSize
wxGrid::SetGridCursor
wxGrid::SetGridLineColour
wxGrid::SetLabelBackgroundColour
wxGrid::SetLabelFont
wxGrid::SetLabelTextColour
wxGrid::SetMargins
wxGrid::SetOrCalcColumnSizes
wxGrid::SetOrCalcRowSizes
wxGrid::SetReadOnly
wxGrid::SetRowAttr
wxGrid::SetRowLabelAlignment
wxGrid::SetRowLabelSize
wxGrid::SetRowLabelValue
wxGrid::SetRowMinimalHeight
wxGrid::SetRowMinimalAcceptableHeight
wxGrid::SetRowSize
wxGrid::SetScrollLineX
wxGrid::SetScrollLineY
wxGrid::SetSelectionBackground
wxGrid::SetSelectionForeground
wxGrid::SetSelectionMode
wxGrid::SetTable
wxGrid::ShowCellEditControl
wxGrid::XToCol
wxGrid::XToEdgeOfCol
wxGrid::YToEdgeOfRow
wxGrid::YToRow
wxGrid
~wxGrid
CreateGrid
SetTable
wxGrid::ClearSelection
wxGrid::IsSelection
wxGrid::SelectAll
wxGrid::SelectBlock
wxGrid::SelectCol
wxGrid::SelectRow
wxGrid()
Default constructor
wxGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxWANTS_CHARS, const wxString& name = wxPanelNameStr)
Constructor to create a grid object. Call either wxGrid::CreateGrid or wxGrid::SetTable directly after this to initialize the grid before using it.
~wxGrid()
Destructor. This will also destroy the associated grid table unless you passed a table object to the grid and specified that the grid should not take ownership of the table (see wxGrid::SetTable).
bool AppendCols(int numCols = 1, bool updateLabels = true)
Appends one or more new columns to the right of the grid and returns true if successful. The updateLabels argument is not used at present.
If you are using a derived grid table class you will need to override wxGridTableBase::AppendCols. See wxGrid::InsertCols for further information.
bool AppendRows(int numRows = 1, bool updateLabels = true)
Appends one or more new rows to the bottom of the grid and returns true if successful. The updateLabels argument is not used at present.
If you are using a derived grid table class you will need to override wxGridTableBase::AppendRows. See wxGrid::InsertRows for further information.
void AutoSize()
Automatically sets the height and width of all rows and columns to fit their contents.
Note
wxGrid sets up arrays to store individual row and column sizes when non-default sizes are used.
The memory requirements for this could become prohibitive if your grid is very large.
void AutoSizeColOrRow(int n, bool setAsMin, bool column)
Common part of AutoSizeColumn/Row() or row?
void AutoSizeColumn(int col, bool setAsMin = true)
Automatically sizes the column to fit its contents. If setAsMin is true the calculated width will also be set as the minimal width for the column.
Note
wxGrid sets up arrays to store individual row and column sizes when non-default sizes are used.
The memory requirements for this could become prohibitive if your grid is very large.
void AutoSizeColumns(bool setAsMin = true)
Automatically sizes all columns to fit their contents. If setAsMin is true the calculated widths will also be set as the minimal widths for the columns.
Note
wxGrid sets up arrays to store individual row and column sizes when non-default sizes are used.
The memory requirements for this could become prohibitive if your grid is very large.
void AutoSizeRow(int row, bool setAsMin = true)
Automatically sizes the row to fit its contents. If setAsMin is true the calculated height will also be set as the minimal height for the row.
Note
wxGrid sets up arrays to store individual row and column sizes when non-default sizes are used.
The memory requirements for this could become prohibitive if your grid is very large.
void AutoSizeRows(bool setAsMin = true)
Automatically sizes all rows to fit their contents. If setAsMin is true the calculated heights will also be set as the minimal heights for the rows.
Note
wxGrid sets up arrays to store individual row and column sizes when non-default sizes are used.
The memory requirements for this could become prohibitive if your grid is very large.
void BeginBatch()
Increments the grid's batch count. When the count is greater than zero repainting of the grid is suppressed. Each call to BeginBatch must be matched by a later call to wxGrid::EndBatch. Code that does a lot of grid modification can be enclosed between BeginBatch and EndBatch calls to avoid screen flicker. The final EndBatch will cause the grid to be repainted.
wxRect BlockToDeviceRect(const wxGridCellCoords & topLeft, const wxGridCellCoords & bottomRight)
This function returns the rectangle that encloses the block of cells limited by TopLeft and BottomRight cell in device coords and clipped to the client size of the grid window.
bool CanDragColMove()
Returns true if columns can be moved by dragging with the mouse. Columns can be moved by dragging on their labels.
bool CanDragColSize()
Returns true if columns can be resized by dragging with the mouse. Columns can be resized by dragging the edges of their labels. If grid line dragging is enabled they can also be resized by dragging the right edge of the column in the grid cell area (see wxGrid::EnableDragGridSize).
bool CanDragRowSize()
Returns true if rows can be resized by dragging with the mouse. Rows can be resized by dragging the edges of their labels. If grid line dragging is enabled they can also be resized by dragging the lower edge of the row in the grid cell area (see wxGrid::EnableDragGridSize).
bool CanDragGridSize()
Return true if the dragging of grid lines to resize rows and columns is enabled or false otherwise.
bool CanEnableCellControl() const
Returns true if the in-place edit control for the current grid cell can be used and false otherwise (e.g. if the current cell is read-only).
bool CanHaveAttributes()
Do we have some place to store attributes in?
wxRect CellToRect(int row, int col)
wxRect CellToRect(const wxGridCellCoords& coords)
Return the rectangle corresponding to the grid cell's size and position in logical coordinates.
void ClearGrid()
Clears all data in the underlying grid table and repaints the grid. The table is not deleted by this function. If you are using a derived table class then you need to override wxGridTableBase::Clear for this function to have any effect.
void ClearSelection()
Deselects all cells that are currently selected.
bool CreateGrid(int numRows, int numCols, wxGrid::wxGridSelectionModes selmode = wxGrid::wxGridSelectCells)
Creates a grid with the specified initial number of rows and columns. Call this directly after the grid constructor. When you use this function wxGrid will create and manage a simple table of string values for you. All of the grid data will be stored in memory.
For applications with more complex data types or relationships, or for dealing with very large datasets, you should derive your own grid table class and pass a table object to the grid with wxGrid::SetTable.
bool DeleteCols(int pos = 0, int numCols = 1, bool updateLabels = true)
Deletes one or more columns from a grid starting at the specified position and returns true if successful. The updateLabels argument is not used at present.
If you are using a derived grid table class you will need to override wxGridTableBase::DeleteCols. See wxGrid::InsertCols for further information.
bool DeleteRows(int pos = 0, int numRows = 1, bool updateLabels = true)
Deletes one or more rows from a grid starting at the specified position and returns true if successful. The updateLabels argument is not used at present.
If you are using a derived grid table class you will need to override wxGridTableBase::DeleteRows. See wxGrid::InsertRows for further information.
void DisableCellEditControl()
Disables in-place editing of grid cells. Equivalent to calling EnableCellEditControl(false).
void DisableDragColMove()
Disables column moving by dragging with the mouse. Equivalent to passing false to wxGrid::EnableDragColMove.
void DisableDragColSize()
Disables column sizing by dragging with the mouse. Equivalent to passing false to wxGrid::EnableDragColSize.
void DisableDragGridSize()
Disable mouse dragging of grid lines to resize rows and columns. Equivalent to passing false to wxGrid::EnableDragGridSize
void DisableDragRowSize()
Disables row sizing by dragging with the mouse. Equivalent to passing false to wxGrid::EnableDragRowSize.
void EnableCellEditControl(bool enable = true)
Enables or disables in-place editing of grid cell data. The grid will issue either a wxEVT_GRID_EDITOR_SHOWN or wxEVT_GRID_EDITOR_HIDDEN event.
void EnableDragColSize(bool enable = true)
Enables or disables column sizing by dragging with the mouse.
void EnableDragColMove(bool enable = true)
Enables or disables column moving by dragging with the mouse.
void EnableDragGridSize(bool enable = true)
Enables or disables row and column resizing by dragging gridlines with the mouse.
void EnableDragRowSize(bool enable = true)
Enables or disables row sizing by dragging with the mouse.
void EnableEditing(bool edit)
If the edit argument is false this function sets the whole grid as read-only. If the argument is true the grid is set to the default state where cells may be editable. In the default state you can set single grid cells and whole rows and columns to be editable or read-only via wxGridCellAttribute::SetReadOnly. For single cells you can also use the shortcut function wxGrid::SetReadOnly.
For more information about controlling grid cell attributes see the wxGridCellAttr cell attribute class and the wxGrid classes overview.
void EnableGridLines(bool enable = true)
Turns the drawing of grid lines on or off.
void EndBatch()
Decrements the grid's batch count. When the count is greater than zero repainting of the grid is suppressed. Each previous call to wxGrid::BeginBatch must be matched by a later call to EndBatch. Code that does a lot of grid modification can be enclosed between BeginBatch and EndBatch calls to avoid screen flicker. The final EndBatch will cause the grid to be repainted.
void Fit()
Overridden wxWindow method.
void ForceRefresh()
Causes immediate repainting of the grid. Use this instead of the usual wxWindow::Refresh.
int GetBatchCount()
Returns the number of times that wxGrid::BeginBatch has been called without (yet) matching calls to wxGrid::EndBatch. While the grid's batch count is greater than zero the display will not be updated.
void GetCellAlignment(int row, int col, int* horiz, int* vert)
Sets the arguments to the horizontal and vertical text alignment values for the grid cell at the specified location.
Horizontal alignment will be one of wxALIGN_LEFT, wxALIGN_CENTRE or wxALIGN_RIGHT.
Vertical alignment will be one of wxALIGN_TOP, wxALIGN_CENTRE or wxALIGN_BOTTOM.
wxColour GetCellBackgroundColour(int row, int col)
Returns the background colour of the cell at the specified location.
wxGridCellEditor* GetCellEditor(int row, int col)
Returns a pointer to the editor for the cell at the specified location.
See wxGridCellEditor and the wxGrid overview for more information about cell editors and renderers.
wxFont GetCellFont(int row, int col)
Returns the font for text in the grid cell at the specified location.
wxGridCellRenderer* GetCellRenderer(int row, int col)
Returns a pointer to the renderer for the grid cell at the specified location.
See wxGridCellRenderer and the wxGrid overview for more information about cell editors and renderers.
wxColour GetCellTextColour(int row, int col)
Returns the text colour for the grid cell at the specified location.
wxString GetCellValue(int row, int col)
wxString GetCellValue(const wxGridCellCoords&coords)
Returns the string contained in the cell at the specified location. For simple applications where a grid object automatically uses a default grid table of string values you use this function together with wxGrid::SetCellValue to access cell values.
For more complex applications where you have derived your own grid table class that contains various data types (e.g. numeric, boolean or user-defined custom types) then you only use this function for those cells that contain string values.
See wxGridTableBase::CanGetValueAs and the wxGrid overview for more information.
int GetColAt(int colPos) const
Returns the column ID of the specified column position.
int GetColLeft(int col) const
void GetColLabelAlignment(int* horiz, int* vert)
Sets the arguments to the current column label alignment values.
Horizontal alignment will be one of wxALIGN_LEFT, wxALIGN_CENTRE or wxALIGN_RIGHT.
Vertical alignment will be one of wxALIGN_TOP, wxALIGN_CENTRE or wxALIGN_BOTTOM.
int GetColLabelSize()
Returns the current height of the column labels.
wxString GetColLabelValue(int col)
Returns the specified column label. The default grid table class provides column labels of the form A,B...Z,AA,AB...ZZ,AAA... If you are using a custom grid table you can override wxGridTableBase::GetColLabelValue to provide your own labels.
int GetColMinimalAcceptableWidth()
This returns the value of the lowest column width that can be handled correctly. See member SetColMinimalAcceptableWidth for details.
int GetColMinimalWidth(int col) const
Get the minimal width of the given column/row.
int GetColPos(int colID) const
Returns the position of the specified column.
int GetColRight(int col) const
int GetColSize(int col)
Returns the width of the specified column.
void GetDefaultCellAlignment(int* horiz, int* vert)
Sets the arguments to the current default horizontal and vertical text alignment values.
Horizontal alignment will be one of wxALIGN_LEFT, wxALIGN_CENTRE or wxALIGN_RIGHT.
Vertical alignment will be one of wxALIGN_TOP, wxALIGN_CENTRE or wxALIGN_BOTTOM.
wxColour GetDefaultCellBackgroundColour()
Returns the current default background colour for grid cells.
wxFont GetDefaultCellFont()
Returns the current default font for grid cell text.
wxColour GetDefaultCellTextColour()
Returns the current default colour for grid cell text.
int GetDefaultColLabelSize()
Returns the default height for column labels.
int GetDefaultColSize()
Returns the current default width for grid columns.
wxGridCellEditor* GetDefaultEditor() const
Returns a pointer to the current default grid cell editor.
See wxGridCellEditor and the wxGrid overview for more information about cell editors and renderers.
wxGridCellEditor* GetDefaultEditorForCell(int row, int col) const
wxGridCellEditor* GetDefaultEditorForCell(const wxGridCellCoords& c) const
wxGridCellEditor* GetDefaultEditorForType(const wxString& typeName) const
wxGridCellRenderer* GetDefaultRenderer() const
Returns a pointer to the current default grid cell renderer.
See wxGridCellRenderer and the wxGrid overview for more information about cell editors and renderers.
wxGridCellRenderer* GetDefaultRendererForCell(int row, int col) const
wxGridCellRenderer* GetDefaultRendererForType(const wxString& typeName) const
int GetDefaultRowLabelSize()
Returns the default width for the row labels.
int GetDefaultRowSize()
Returns the current default height for grid rows.
int GetGridCursorCol()
Returns the current grid cell column position.
int GetGridCursorRow()
Returns the current grid cell row position.
wxColour GetGridLineColour()
Returns the colour used for grid lines.
See also
wxPen GetDefaultGridLinePen()
Returns the pen used for grid lines. This virtual function may be overridden in derived classes in order to change the appearance of grid lines. Note that currently the pen width must be 1.
See also
GetColGridLinePen(),
GetRowGridLinePen()
wxPen GetRowGridLinePen(int row)
Returns the pen used for horizontal grid lines. This virtual function may be overridden in derived classes in order to change the appearance of individual grid line for the given row row.
Example:
// in a grid displaying music notation, use a solid black pen between // octaves (C0=row 127, C1=row 115 etc.) wxPen MidiGrid::GetRowGridLinePen(int row) { if ( row%12 == 7 ) return wxPen(*wxBLACK, 1, wxSOLID); else return GetDefaultGridLinePen(); }
wxPen GetColGridLinePen(int col)
Returns the pen used for vertical grid lines. This virtual function may be overridden in derived classes in order to change the appearance of individual grid lines for the given column col.
See GetRowGridLinePen() for an example.
bool GridLinesEnabled()
Returns true if drawing of grid lines is turned on, false otherwise.
wxColour GetLabelBackgroundColour()
Returns the colour used for the background of row and column labels.
wxFont GetLabelFont()
Returns the font used for row and column labels.
wxColour GetLabelTextColour()
Returns the colour used for row and column label text.
int GetNumberCols()
Returns the total number of grid columns (actually the number of columns in the underlying grid table).
int GetNumberRows()
Returns the total number of grid rows (actually the number of rows in the underlying grid table).
wxGridCellAttr* GetOrCreateCellAttr(int row, int col) const
int GetRowMinimalAcceptableHeight()
This returns the value of the lowest row width that can be handled correctly. See member SetRowMinimalAcceptableHeight for details.
int GetRowMinimalHeight(int col) const
void GetRowLabelAlignment(int* horiz, int* vert)
Sets the arguments to the current row label alignment values.
Horizontal alignment will be one of wxLEFT, wxCENTRE or wxRIGHT.
Vertical alignment will be one of wxTOP, wxCENTRE or wxBOTTOM.
int GetRowLabelSize()
Returns the current width of the row labels.
wxString GetRowLabelValue(int row)
Returns the specified row label. The default grid table class provides numeric row labels. If you are using a custom grid table you can override wxGridTableBase::GetRowLabelValue to provide your own labels.
int GetRowSize(int row)
Returns the height of the specified row.
int GetScrollLineX() const
Returns the number of pixels per horizontal scroll increment. The default is 15.
See also
wxGrid::GetScrollLineY, wxGrid::SetScrollLineX, wxGrid::SetScrollLineY
int GetScrollLineY() const
Returns the number of pixels per vertical scroll increment. The default is 15.
See also
wxGrid::GetScrollLineX, wxGrid::SetScrollLineX, wxGrid::SetScrollLineY
wxGrid::wxGridSelectionModes GetSelectionMode() const
Returns the current selection mode, see wxGrid::SetSelectionMode.
wxGridCellCoordsArray GetSelectedCells() const
Returns an array of singly selected cells.
wxArrayInt GetSelectedCols() const
Returns an array of selected cols.
wxArrayInt GetSelectedRows() const
Returns an array of selected rows.
wxColour GetSelectionBackground() const
Access or update the selection fore/back colours
wxGridCellCoordsArray GetSelectionBlockTopLeft() const
Returns an array of the top left corners of blocks of selected cells, see wxGrid::GetSelectionBlockBottomRight.
wxGridCellCoordsArray GetSelectionBlockBottomRight() const
Returns an array of the bottom right corners of blocks of selected cells, see wxGrid::GetSelectionBlockTopLeft.
wxColour GetSelectionForeground() const
wxGridTableBase * GetTable() const
Returns a base pointer to the current table object.
int GetViewWidth()
Returned number of whole cols visible.
void HideCellEditControl()
Hides the in-place cell edit control.
void InitColWidths()
Init the m_colWidths/Rights arrays
void InitRowHeights()
NB: never access m_row/col arrays directly because they are created on demand, always use accessor functions instead!
Init the m_rowHeights/Bottoms arrays with default values.
bool InsertCols(int pos = 0, int numCols = 1, bool updateLabels = true)
Inserts one or more new columns into a grid with the first new column at the specified position and returns true if successful. The updateLabels argument is not used at present.
The sequence of actions begins with the grid object requesting the underlying grid table to insert new columns. If this is successful the table notifies the grid and the grid updates the display. For a default grid (one where you have called wxGrid::CreateGrid) this process is automatic. If you are using a custom grid table (specified with wxGrid::SetTable) then you must override wxGridTableBase::InsertCols in your derived table class.
bool InsertRows(int pos = 0, int numRows = 1, bool updateLabels = true)
Inserts one or more new rows into a grid with the first new row at the specified position and returns true if successful. The updateLabels argument is not used at present.
The sequence of actions begins with the grid object requesting the underlying grid table to insert new rows. If this is successful the table notifies the grid and the grid updates the display. For a default grid (one where you have called wxGrid::CreateGrid) this process is automatic. If you are using a custom grid table (specified with wxGrid::SetTable) then you must override wxGridTableBase::InsertRows in your derived table class.
bool IsCellEditControlEnabled() const
Returns true if the in-place edit control is currently enabled.
bool IsCurrentCellReadOnly() const
Returns true if the current cell has been set to read-only (see wxGrid::SetReadOnly).
bool IsEditable()
Returns false if the whole grid has been set as read-only or true otherwise. See wxGrid::EnableEditing for more information about controlling the editing status of grid cells.
bool IsInSelection(int row, int col) const
bool IsInSelection(const wxGridCellCoords& coords) const
Is this cell currently selected.
bool IsReadOnly(int row, int col) const
Returns true if the cell at the specified location can't be edited. See also wxGrid::IsReadOnly.
bool IsSelection()
Returns true if there are currently rows, columns or blocks of cells selected.
bool IsVisible(int row, int col, bool wholeCellVisible = true)
bool IsVisible(const wxGridCellCoords& coords, bool wholeCellVisible = true)
Returns true if a cell is either wholly visible (the default) or at least partially visible in the grid window.
void MakeCellVisible(int row, int col)
void MakeCellVisible(const wxGridCellCoords& coords)
Brings the specified cell into the visible grid cell area with minimal scrolling. Does nothing if the cell is already visible.
bool MoveCursorDown(bool expandSelection)
Moves the grid cursor down by one row. If a block of cells was previously selected it will expand if the argument is true or be cleared if the argument is false.
Keyboard
This function is called for Down cursor key presses or Shift+Down to expand a selection.
bool MoveCursorLeft(bool expandSelection)
Moves the grid cursor left by one column. If a block of cells was previously selected it will expand if the argument is true or be cleared if the argument is false.
Keyboard
This function is called for Left cursor key presses or Shift+Left to expand a selection.
bool MoveCursorRight(bool expandSelection)
Moves the grid cursor right by one column. If a block of cells was previously selected it will expand if the argument is true or be cleared if the argument is false.
Keyboard
This function is called for Right cursor key presses or Shift+Right to expand a selection.
bool MoveCursorUp(bool expandSelection)
Moves the grid cursor up by one row. If a block of cells was previously selected it will expand if the argument is true or be cleared if the argument is false.
Keyboard
This function is called for Up cursor key presses or Shift+Up to expand a selection.
bool MoveCursorDownBlock(bool expandSelection)
Moves the grid cursor down in the current column such that it skips to the beginning or end of a block of non-empty cells. If a block of cells was previously selected it will expand if the argument is true or be cleared if the argument is false.
Keyboard
This function is called for the Ctrl+Down key combination. Shift+Ctrl+Down expands a selection.
bool MoveCursorLeftBlock(bool expandSelection)
Moves the grid cursor left in the current row such that it skips to the beginning or end of a block of non-empty cells. If a block of cells was previously selected it will expand if the argument is true or be cleared if the argument is false.
Keyboard
This function is called for the Ctrl+Left key combination. Shift+Ctrl+left expands a selection.
bool MoveCursorRightBlock(bool expandSelection)
Moves the grid cursor right in the current row such that it skips to the beginning or end of a block of non-empty cells. If a block of cells was previously selected it will expand if the argument is true or be cleared if the argument is false.
Keyboard
This function is called for the Ctrl+Right key combination. Shift+Ctrl+Right expands a selection.
bool MoveCursorUpBlock(bool expandSelection)
Moves the grid cursor up in the current column such that it skips to the beginning or end of a block of non-empty cells. If a block of cells was previously selected it will expand if the argument is true or be cleared if the argument is false.
Keyboard
This function is called for the Ctrl+Up key combination. Shift+Ctrl+Up expands a selection.
bool MovePageDown()
Moves the grid cursor down by some number of rows so that the previous bottom visible row becomes the top visible row.
Keyboard
This function is called for PgDn keypresses.
bool MovePageUp()
Moves the grid cursor up by some number of rows so that the previous top visible row becomes the bottom visible row.
Keyboard
This function is called for PgUp keypresses.
void RegisterDataType(const wxString& typeName, wxGridCellRenderer* renderer, wxGridCellEditor* editor)
Methods for a registry for mapping data types to Renderers/Editors
void SaveEditControlValue()
Sets the value of the current grid cell to the current in-place edit control value. This is called automatically when the grid cursor moves from the current cell to a new cell. It is also a good idea to call this function when closing a grid since any edits to the final cell location will not be saved otherwise.
void SelectAll()
Selects all cells in the grid.
void SelectBlock(int topRow, int leftCol, int bottomRow, int rightCol, bool addToSelected = false)
void SelectBlock(const wxGridCellCoords& topLeft, const wxGridCellCoords& bottomRight, bool addToSelected = false)
Selects a rectangular block of cells. If addToSelected is false then any existing selection will be deselected; if true the column will be added to the existing selection.
void SelectCol(int col, bool addToSelected = false)
Selects the specified column. If addToSelected is false then any existing selection will be deselected; if true the column will be added to the existing selection.
wxRect SelectionToDeviceRect()
This function returns the rectangle that encloses the selected cells in device coords and clipped to the client size of the grid window.
void SelectRow(int row, bool addToSelected = false)
Selects the specified row. If addToSelected is false then any existing selection will be deselected; if true the row will be added to the existing selection.
void SetCellAlignment(int row, int col, int horiz, int vert)
void SetCellAlignment(int align, int row, int col)
Sets the horizontal and vertical alignment for grid cell text at the specified location.
Horizontal alignment should be one of wxALIGN_LEFT, wxALIGN_CENTRE or wxALIGN_RIGHT.
Vertical alignment should be one of wxALIGN_TOP, wxALIGN_CENTRE or wxALIGN_BOTTOM.
void SetCellBackgroundColour(int row, int col, const wxColour& colour)
void SetCellEditor(int row, int col, wxGridCellEditor* editor)
Sets the editor for the grid cell at the specified location. The grid will take ownership of the pointer.
See wxGridCellEditor and the wxGrid overview for more information about cell editors and renderers.
void SetCellFont(int row, int col, const wxFont& font)
Sets the font for text in the grid cell at the specified location.
void SetCellRenderer(int row, int col, wxGridCellRenderer* renderer)
Sets the renderer for the grid cell at the specified location. The grid will take ownership of the pointer.
See wxGridCellRenderer and the wxGrid overview for more information about cell editors and renderers.
void SetCellTextColour(int row, int col, const wxColour& colour)
void SetCellTextColour(const wxColour& val, int row, int col)
void SetCellTextColour(const wxColour& colour)
Sets the text colour for the grid cell at the specified location.
void SetCellValue(int row, int col, const wxString& s)
void SetCellValue(const wxGridCellCoords& coords, const wxString& s)
void SetCellValue(const wxString& val, int row, int col)
Sets the string value for the cell at the specified location. For simple applications where a grid object automatically uses a default grid table of string values you use this function together with wxGrid::GetCellValue to access cell values.
For more complex applications where you have derived your own grid table class that contains various data types (e.g. numeric, boolean or user-defined custom types) then you only use this function for those cells that contain string values.
The last form is for backward compatibility only.
See wxGridTableBase::CanSetValueAs and the wxGrid overview for more information.
void SetColAttr(int col, wxGridCellAttr* attr)
Sets the cell attributes for all cells in the specified column.
For more information about controlling grid cell attributes see the wxGridCellAttr cell attribute class and the wxGrid classes overview.
void SetColFormatBool(int col)
Sets the specified column to display boolean values. wxGrid displays boolean values with a checkbox.
void SetColFormatNumber(int col)
Sets the specified column to display integer values.
void SetColFormatFloat(int col, int width = -1, int precision = -1)
Sets the specified column to display floating point values with the given width and precision.
void SetColFormatCustom(int col, const wxString& typeName)
Sets the specified column to display data in a custom format. See the wxGrid overview for more information on working with custom data types.
void SetColLabelAlignment(int horiz, int vert)
Sets the horizontal and vertical alignment of column label text.
Horizontal alignment should be one of wxALIGN_LEFT, wxALIGN_CENTRE or wxALIGN_RIGHT.
Vertical alignment should be one of wxALIGN_TOP, wxALIGN_CENTRE or wxALIGN_BOTTOM.
void SetColLabelSize(int height)
Sets the height of the column labels.
void SetColLabelValue(int col, const wxString& value)
Set the value for the given column label. If you are using a derived grid table you must override wxGridTableBase::SetColLabelValue for this to have any effect.
void SetColMinimalWidth(int col, int width)
Sets the minimal width for the specified column. This should normally be called when creating the grid because it will not resize a column that is already narrower than the minimal width. The width argument must be higher than the minimimal acceptable column width, see wxGrid::GetColMinimalAcceptableWidth.
void SetColMinimalAcceptableWidth(int width)
This modifies the minimum column width that can be handled correctly. Specifying a low value here allows smaller grid cells to be dealt with correctly. Specifying a value here which is much smaller than the actual minimum size will incur a performance penalty in the functions which perform grid cell index lookup on the basis of screen coordinates. This should normally be called when creating the grid because it will not resize existing columns with sizes smaller than the value specified here.
void SetColPos(int colID, int newPos)
Sets the position of the specified column.
void SetColSize(int col, int width)
Sets the width of the specified column.
This function does not refresh the grid. If you are calling it outside of a BeginBatch / EndBatch block you can use wxGrid::ForceRefresh to see the changes.
Automatically sizes the column to fit its contents. If setAsMin is true the calculated width will also be set as the minimal width for the column.
Note
wxGrid sets up arrays to store individual row and column sizes when non-default sizes are used.
The memory requirements for this could become prohibitive if your grid is very large.
void SetDefaultCellAlignment(int horiz, int vert)
Sets the default horizontal and vertical alignment for grid cell text.
Horizontal alignment should be one of wxALIGN_LEFT, wxALIGN_CENTRE or wxALIGN_RIGHT.
Vertical alignment should be one of wxALIGN_TOP, wxALIGN_CENTRE or wxALIGN_BOTTOM.
void SetDefaultCellBackgroundColour(const wxColour& colour)
Sets the default background colour for grid cells.
void SetDefaultCellFont(const wxFont& font)
Sets the default font to be used for grid cell text.
void SetDefaultCellTextColour(const wxColour& colour)
Sets the current default colour for grid cell text.
void SetDefaultEditor(wxGridCellEditor* editor)
Sets the default editor for grid cells. The grid will take ownership of the pointer.
See wxGridCellEditor and the wxGrid overview for more information about cell editors and renderers.
void SetDefaultRenderer(wxGridCellRenderer* renderer)
Sets the default renderer for grid cells. The grid will take ownership of the pointer.
See wxGridCellRenderer and the wxGrid overview for more information about cell editors and renderers.
void SetDefaultColSize(int width, bool resizeExistingCols = false)
Sets the default width for columns in the grid. This will only affect columns subsequently added to the grid unless resizeExistingCols is true.
void SetDefaultRowSize(int height, bool resizeExistingRows = false)
Sets the default height for rows in the grid. This will only affect rows subsequently added to the grid unless resizeExistingRows is true.
void SetGridCursor(int row, int col)
Set the grid cursor to the specified cell. This function calls wxGrid::MakeCellVisible.
void SetGridLineColour(const wxColour&colour)
Sets the colour used to draw grid lines.
void SetLabelBackgroundColour(const wxColour& colour)
Sets the background colour for row and column labels.
void SetLabelFont(const wxFont& font)
Sets the font for row and column labels.
void SetLabelTextColour(const wxColour& colour)
Sets the colour for row and column label text.
void SetMargins(int extraWidth, int extraHeight)
A grid may occupy more space than needed for its rows/columns. This function allows to set how big this extra space is
int SetOrCalcColumnSizes(bool calcOnly, bool setAsMin = true)
Common part of AutoSizeColumn/Row() and GetBestSize()
int SetOrCalcRowSizes(bool calcOnly, bool setAsMin = true)
void SetReadOnly(int row, int col, bool isReadOnly = true)
Makes the cell at the specified location read-only or editable. See also wxGrid::IsReadOnly.
void SetRowAttr(int row, wxGridCellAttr* attr)
Sets the cell attributes for all cells in the specified row. See the wxGridCellAttr class for more information about controlling cell attributes.
void SetRowLabelAlignment(int horiz, int vert)
Sets the horizontal and vertical alignment of row label text.
Horizontal alignment should be one of wxALIGN_LEFT, wxALIGN_CENTRE or wxALIGN_RIGHT.
Vertical alignment should be one of wxALIGN_TOP, wxALIGN_CENTRE or wxALIGN_BOTTOM.
void SetRowLabelSize(int width)
Sets the width of the row labels.
void SetRowLabelValue(int row, const wxString& value)
Set the value for the given row label. If you are using a derived grid table you must override wxGridTableBase::SetRowLabelValue for this to have any effect.
void SetRowMinimalHeight(int row, int height)
Sets the minimal height for the specified row. This should normally be called when creating the grid because it will not resize a row that is already shorter than the minimal height. The height argument must be higher than the minimimal acceptable row height, see wxGrid::GetRowMinimalAcceptableHeight.
void SetRowMinimalAcceptableHeight(int height)
This modifies the minimum row width that can be handled correctly. Specifying a low value here allows smaller grid cells to be dealt with correctly. Specifying a value here which is much smaller than the actual minimum size will incur a performance penalty in the functions which perform grid cell index lookup on the basis of screen coordinates. This should normally be called when creating the grid because it will not resize existing rows with sizes smaller than the value specified here.
void SetRowSize(int row, int height)
Sets the height of the specified row.
This function does not refresh the grid. If you are calling it outside of a BeginBatch / EndBatch block you can use wxGrid::ForceRefresh to see the changes.
Automatically sizes the column to fit its contents. If setAsMin is true the calculated width will also be set as the minimal width for the column.
Note
wxGrid sets up arrays to store individual row and column sizes when non-default sizes are used. The memory requirements for this could become prohibitive if your grid is very large.
void SetScrollLineX(int x)
Sets the number of pixels per horizontal scroll increment. The default is 15. Sometimes wxGrid has trouble setting the scrollbars correctly due to rounding errors: setting this to 1 can help.
See also
wxGrid::GetScrollLineX, wxGrid::GetScrollLineY, wxGrid::SetScrollLineY
void SetScrollLineY(int y)
Sets the number of pixels per vertical scroll increment. The default is 15. Sometimes wxGrid has trouble setting the scrollbars correctly due to rounding errors: setting this to 1 can help.
See also
wxGrid::GetScrollLineX, wxGrid::GetScrollLineY, wxGrid::SetScrollLineX
void SetSelectionBackground(const wxColour& c)
void SetSelectionForeground(const wxColour& c)
void SetSelectionMode(wxGrid::wxGridSelectionModes selmode)
Set the selection behaviour of the grid.
Parameters
wxGrid::wxGridSelectCells
wxGrid::wxGridSelectRows
wxGrid::wxGridSelectColumns
bool SetTable(wxGridTableBase* table, bool takeOwnership = false, wxGrid::wxGridSelectionModes selmode = wxGrid::wxGridSelectCells)
Passes a pointer to a custom grid table to be used by the grid. This should be called after the grid constructor and before using the grid object. If takeOwnership is set to true then the table will be deleted by the wxGrid destructor.
Use this function instead of wxGrid::CreateGrid when your application involves complex or non-string data or data sets that are too large to fit wholly in memory.
void ShowCellEditControl()
Displays the in-place cell edit control for the current cell.
int XToCol(int x, bool clipToMinMax = false)
Parameters x
Return value The grid column that corresponds to the logical x coordinate. Returns wxNOT_FOUND if there is no column at the x position.
int XToEdgeOfCol(int x)
Returns the column whose right hand edge is close to the given logical x position. If no column edge is near to this position wxNOT_FOUND is returned.
int YToEdgeOfRow(int y)
Returns the row whose bottom edge is close to the given logical y position. If no row edge is near to this position wxNOT_FOUND is returned.
int YToRow(int y)
Returns the grid row that corresponds to the logical y coordinate. Returns wxNOT_FOUND if there is no row at the y position.