Version: 3.1.0
wxGrid Class Reference

#include <wx/grid.h>

+ Inheritance diagram for wxGrid:

Detailed Description

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 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.

A wxGridTableBase class holds the actual data to be displayed by a wxGrid class. One or more wxGrid classes may act as a view for one table class. The default table class is called wxGridStringTable and holds an array of strings. An instance of such a class is created by CreateGrid().

wxGridCellRenderer is the abstract base class for rendering contents in a cell. The following renderers are predefined:

The look of a cell can be further defined using wxGridCellAttr. An object of this type may be returned by wxGridTableBase::GetAttr().

wxGridCellEditor is the abstract base class for editing the value of a cell. The following editors are predefined:

Please see wxGridEvent, wxGridSizeEvent, wxGridRangeSelectEvent, and wxGridEditorCreatedEvent for the documentation of all event types you can use with wxGrid.

Library:  wxAdvanced
Category:  Grid Related Classes
See Also
wxGrid Overview, wxGridUpdateLocker

Public Types

enum  wxGridSelectionModes {
  wxGridSelectCells,
  wxGridSelectRows,
  wxGridSelectColumns,
  wxGridSelectRowsOrColumns
}
 Different selection modes supported by the grid. More...
 
enum  CellSpan {
  CellSpan_Inside = -1,
  CellSpan_None = 0,
  CellSpan_Main
}
 Return values for GetCellSize(). More...
 
enum  TabBehaviour {
  Tab_Stop,
  Tab_Wrap,
  Tab_Leave
}
 Constants defining different support built-in TAB handling behaviours. More...
 

Public Member Functions

virtual void DrawCellHighlight (wxDC &dc, const wxGridCellAttr *attr)
 
virtual void DrawRowLabels (wxDC &dc, const wxArrayInt &rows)
 
virtual void DrawRowLabel (wxDC &dc, int row)
 
virtual void DrawColLabels (wxDC &dc, const wxArrayInt &cols)
 
virtual void DrawColLabel (wxDC &dc, int col)
 
virtual void DrawCornerLabel (wxDC &dc)
 
void DrawTextRectangle (wxDC &dc, const wxString &text, const wxRect &rect, int horizontalAlignment=wxALIGN_LEFT, int verticalAlignment=wxALIGN_TOP, int textOrientation=wxHORIZONTAL) const
 
void DrawTextRectangle (wxDC &dc, const wxArrayString &lines, const wxRect &rect, int horizontalAlignment=wxALIGN_LEFT, int verticalAlignment=wxALIGN_TOP, int textOrientation=wxHORIZONTAL) const
 
wxColour GetCellHighlightColour () const
 
int GetCellHighlightPenWidth () const
 
int GetCellHighlightROPenWidth () const
 
void SetCellHighlightColour (const wxColour &)
 
void SetCellHighlightPenWidth (int width)
 
void SetCellHighlightROPenWidth (int width)
 
Constructors and Initialization
 wxGrid ()
 Default constructor.
 
 wxGrid (wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxWANTS_CHARS, const wxString &name=wxGridNameStr)
 Constructor creating the grid window.
 
virtual ~wxGrid ()
 Destructor.
 
bool Create (wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxWANTS_CHARS, const wxString &name=wxGridNameStr)
 Creates the grid window for an object initialized using the default constructor.
 
bool CreateGrid (int numRows, int numCols, wxGridSelectionModes selmode=wxGridSelectCells)
 Creates a grid with the specified initial number of rows and columns.
 
bool SetTable (wxGridTableBase *table, bool takeOwnership=false, wxGridSelectionModes selmode=wxGridSelectCells)
 Passes a pointer to a custom grid table to be used by the grid.
 
bool ProcessTableMessage (wxGridTableMessage &msg)
 Receive and handle a message from the table.
 
Grid Line Formatting
void EnableGridLines (bool enable=true)
 Turns the drawing of grid lines on or off.
 
virtual wxPen GetColGridLinePen (int col)
 Returns the pen used for vertical grid lines.
 
virtual wxPen GetDefaultGridLinePen ()
 Returns the pen used for grid lines.
 
wxColour GetGridLineColour () const
 Returns the colour used for grid lines.
 
virtual wxPen GetRowGridLinePen (int row)
 Returns the pen used for horizontal grid lines.
 
bool GridLinesEnabled () const
 Returns true if drawing of grid lines is turned on, false otherwise.
 
void SetGridLineColour (const wxColour &colour)
 Sets the colour used to draw grid lines.
 
Label Values and Formatting
void GetColLabelAlignment (int *horiz, int *vert) const
 Sets the arguments to the current column label alignment values.
 
int GetColLabelTextOrientation () const
 Returns the orientation of the column labels (either wxHORIZONTAL or wxVERTICAL).
 
wxString GetColLabelValue (int col) const
 Returns the specified column label.
 
wxColour GetLabelBackgroundColour () const
 Returns the colour used for the background of row and column labels.
 
wxFont GetLabelFont () const
 Returns the font used for row and column labels.
 
wxColour GetLabelTextColour () const
 Returns the colour used for row and column label text.
 
void GetRowLabelAlignment (int *horiz, int *vert) const
 Returns the alignment used for row labels.
 
wxString GetRowLabelValue (int row) const
 Returns the specified row label.
 
void HideColLabels ()
 Hides the column labels by calling SetColLabelSize() with a size of 0.
 
void HideRowLabels ()
 Hides the row labels by calling SetRowLabelSize() with a size of 0.
 
void SetColLabelAlignment (int horiz, int vert)
 Sets the horizontal and vertical alignment of column label text.
 
void SetColLabelTextOrientation (int textOrientation)
 Sets the orientation of the column labels (either wxHORIZONTAL or wxVERTICAL).
 
void SetColLabelValue (int col, const wxString &value)
 Set the value for the given column label.
 
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 SetRowLabelAlignment (int horiz, int vert)
 Sets the horizontal and vertical alignment of row label text.
 
void SetRowLabelValue (int row, const wxString &value)
 Sets the value for the given row label.
 
void SetUseNativeColLabels (bool native=true)
 Call this in order to make the column labels use a native look by using wxRendererNative::DrawHeaderButton() internally.
 
void UseNativeColHeader (bool native=true)
 Enable the use of native header window for column labels.
 
Cell Formatting

Note that wxGridCellAttr can be used alternatively to most of these methods.

See the "Attributes Management" of wxGridTableBase.

void GetCellAlignment (int row, int col, int *horiz, int *vert) const
 Sets the arguments to the horizontal and vertical text alignment values for the grid cell at the specified location.
 
wxColour GetCellBackgroundColour (int row, int col) const
 Returns the background colour of the cell at the specified location.
 
wxFont GetCellFont (int row, int col) const
 Returns the font for text in the grid cell at the specified location.
 
wxColour GetCellTextColour (int row, int col) const
 Returns the text colour for the grid cell at the specified location.
 
void GetDefaultCellAlignment (int *horiz, int *vert) const
 Returns the default cell alignment.
 
wxColour GetDefaultCellBackgroundColour () const
 Returns the current default background colour for grid cells.
 
wxFont GetDefaultCellFont () const
 Returns the current default font for grid cell text.
 
wxColour GetDefaultCellTextColour () const
 Returns the current default colour for grid cell text.
 
void SetCellAlignment (int row, int col, int horiz, int vert)
 Sets the horizontal and vertical alignment for grid cell text at the specified location.
 
void SetCellAlignment (int align, int row, int col)
 Sets the horizontal and vertical alignment for grid cell text at the specified location.
 
void SetCellBackgroundColour (int row, int col, const wxColour &colour)
 Set the background colour for the given cell or all cells by default.
 
void SetCellFont (int row, int col, const wxFont &font)
 Sets the font for text in the grid cell at the specified location.
 
void SetCellTextColour (int row, int col, const wxColour &colour)
 Sets the text colour for the given cell.
 
void SetCellTextColour (const wxColour &val, int row, int col)
 Sets the text colour for the given cell.
 
void SetCellTextColour (const wxColour &colour)
 Sets the text colour for all cells by default.
 
void SetDefaultCellAlignment (int horiz, int vert)
 Sets the default horizontal and vertical alignment for grid cell text.
 
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.
 
Cell Values, Editors, and Renderers

Note that wxGridCellAttr can be used alternatively to most of these methods.

See the "Attributes Management" of wxGridTableBase.

bool CanEnableCellControl () const
 Returns true if the in-place edit control for the current grid cell can be used and false otherwise.
 
void DisableCellEditControl ()
 Disables in-place editing of grid cells.
 
void EnableCellEditControl (bool enable=true)
 Enables or disables in-place editing of grid cell data.
 
void EnableEditing (bool edit)
 Makes the grid globally editable or read-only.
 
wxGridCellEditorGetCellEditor (int row, int col) const
 Returns a pointer to the editor for the cell at the specified location.
 
wxGridCellRendererGetCellRenderer (int row, int col) const
 Returns a pointer to the renderer for the grid cell at the specified location.
 
wxString GetCellValue (int row, int col) const
 Returns the string contained in the cell at the specified location.
 
wxString GetCellValue (const wxGridCellCoords &coords) const
 Returns the string contained in the cell at the specified location.
 
wxGridCellEditorGetDefaultEditor () const
 Returns a pointer to the current default grid cell editor.
 
virtual wxGridCellEditorGetDefaultEditorForCell (int row, int col) const
 Returns the default editor for the specified cell.
 
wxGridCellEditorGetDefaultEditorForCell (const wxGridCellCoords &c) const
 Returns the default editor for the specified cell.
 
virtual wxGridCellEditorGetDefaultEditorForType (const wxString &typeName) const
 Returns the default editor for the cells containing values of the given type.
 
wxGridCellRendererGetDefaultRenderer () const
 Returns a pointer to the current default grid cell renderer.
 
virtual wxGridCellRendererGetDefaultRendererForCell (int row, int col) const
 Returns the default renderer for the given cell.
 
virtual wxGridCellRendererGetDefaultRendererForType (const wxString &typeName) const
 Returns the default renderer for the cell containing values of the given type.
 
void HideCellEditControl ()
 Hides the in-place cell edit control.
 
bool IsCellEditControlEnabled () const
 Returns true if the in-place edit control is currently enabled.
 
bool IsCurrentCellReadOnly () const
 Returns true if the current cell is read-only.
 
bool IsEditable () const
 Returns false if the whole grid has been set as read-only or true otherwise.
 
bool IsReadOnly (int row, int col) const
 Returns true if the cell at the specified location can't be edited.
 
void RegisterDataType (const wxString &typeName, wxGridCellRenderer *renderer, wxGridCellEditor *editor)
 Register a new data type.
 
void SaveEditControlValue ()
 Sets the value of the current grid cell to the current in-place edit control value.
 
void SetCellEditor (int row, int col, wxGridCellEditor *editor)
 Sets the editor for 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.
 
void SetCellValue (int row, int col, const wxString &s)
 Sets the string value for the cell at the specified location.
 
void SetCellValue (const wxGridCellCoords &coords, const wxString &s)
 Sets the string value for the cell at the specified location.
 
void SetCellValue (const wxString &val, int row, int col)
 
void SetColFormatBool (int col)
 Sets the specified column to display boolean values.
 
void SetColFormatCustom (int col, const wxString &typeName)
 Sets the specified column to display data in a custom format.
 
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 SetColFormatNumber (int col)
 Sets the specified column to display integer values.
 
void SetDefaultEditor (wxGridCellEditor *editor)
 Sets the default editor for grid cells.
 
void SetDefaultRenderer (wxGridCellRenderer *renderer)
 Sets the default renderer for grid cells.
 
void SetReadOnly (int row, int col, bool isReadOnly=true)
 Makes the cell at the specified location read-only or editable.
 
void ShowCellEditControl ()
 Displays the in-place cell edit control for the current cell.
 
Column and Row Sizes
void AutoSize ()
 Automatically sets the height and width of all rows and columns to fit their contents.
 
void AutoSizeColLabelSize (int col)
 Automatically adjusts width of the column to fit its label.
 
void AutoSizeColumn (int col, bool setAsMin=true)
 Automatically sizes the column to fit its contents.
 
void AutoSizeColumns (bool setAsMin=true)
 Automatically sizes all columns to fit their contents.
 
void AutoSizeRow (int row, bool setAsMin=true)
 Automatically sizes the row to fit its contents.
 
void AutoSizeRowLabelSize (int col)
 Automatically adjusts height of the row to fit its label.
 
void AutoSizeRows (bool setAsMin=true)
 Automatically sizes all rows to fit their contents.
 
bool GetCellOverflow (int row, int col) const
 Returns true if the cell value can overflow.
 
int GetColLabelSize () const
 Returns the current height of the column labels.
 
int GetColMinimalAcceptableWidth () const
 Returns the minimal width to which a column may be resized.
 
int GetColSize (int col) const
 Returns the width of the specified column.
 
bool IsColShown (int col) const
 Returns true if the specified column is not currently hidden.
 
bool GetDefaultCellOverflow () const
 Returns true if the cells can overflow by default.
 
int GetDefaultColLabelSize () const
 Returns the default height for column labels.
 
int GetDefaultColSize () const
 Returns the current default width for grid columns.
 
int GetDefaultRowLabelSize () const
 Returns the default width for the row labels.
 
int GetDefaultRowSize () const
 Returns the current default height for grid rows.
 
int GetRowMinimalAcceptableHeight () const
 Returns the minimal size to which rows can be resized.
 
int GetRowLabelSize () const
 Returns the current width of the row labels.
 
int GetRowSize (int row) const
 Returns the height of the specified row.
 
bool IsRowShown (int row) const
 Returns true if the specified row is not currently hidden.
 
void SetCellOverflow (int row, int col, bool allow)
 Sets the overflow permission of the cell.
 
void SetColLabelSize (int height)
 Sets the height of the column labels.
 
void SetColMinimalAcceptableWidth (int width)
 Sets the minimal width to which the user can resize columns.
 
void SetColMinimalWidth (int col, int width)
 Sets the minimal width for the specified column col.
 
void SetColSize (int col, int width)
 Sets the width of the specified column.
 
void HideCol (int col)
 Hides the specified column.
 
void ShowCol (int col)
 Shows the previously hidden column by resizing it to non-0 size.
 
void SetDefaultCellOverflow (bool allow)
 Sets the default overflow permission of the cells.
 
void SetDefaultColSize (int width, bool resizeExistingCols=false)
 Sets the default width for columns in the grid.
 
void SetDefaultRowSize (int height, bool resizeExistingRows=false)
 Sets the default height for rows in the grid.
 
void SetRowLabelSize (int width)
 Sets the width of the row labels.
 
void SetRowMinimalAcceptableHeight (int height)
 Sets the minimal row height used by default.
 
void SetRowMinimalHeight (int row, int height)
 Sets the minimal height for the specified row.
 
void SetRowSize (int row, int height)
 Sets the height of the specified row.
 
void HideRow (int col)
 Hides the specified row.
 
void ShowRow (int col)
 Shows the previously hidden row.
 
wxGridSizesInfo GetColSizes () const
 Get size information for all columns at once.
 
wxGridSizesInfo GetRowSizes () const
 Get size information for all row at once.
 
void SetColSizes (const wxGridSizesInfo &sizeInfo)
 Restore all columns sizes.
 
void SetRowSizes (const wxGridSizesInfo &sizeInfo)
 Restore all rows sizes.
 
void SetCellSize (int row, int col, int num_rows, int num_cols)
 Set the size of the cell.
 
CellSpan GetCellSize (int row, int col, int *num_rows, int *num_cols) const
 Get the size of the cell in number of cells covered by it.
 
wxSize GetCellSize (const wxGridCellCoords &coords)
 Get the number of rows and columns allocated for this cell.
 
User-Resizing and Dragging

Functions controlling various interactive mouse operations.

By default, columns and rows can be resized by dragging the edges of their labels (this can be disabled using DisableDragColSize() and DisableDragRowSize() methods). And if grid line dragging is enabled with EnableDragGridSize() they can also be resized by dragging the right or bottom edge of the grid cells.

Columns can also be moved to interactively change their order but this needs to be explicitly enabled with EnableDragColMove().

bool CanDragCell () const
 Return true if the dragging of cells is enabled or false otherwise.
 
bool CanDragColMove () const
 Returns true if columns can be moved by dragging with the mouse.
 
bool CanDragColSize (int col) const
 Returns true if the given column can be resized by dragging with the mouse.
 
bool CanDragGridSize () const
 Return true if the dragging of grid lines to resize rows and columns is enabled or false otherwise.
 
bool CanDragRowSize (int row) const
 Returns true if the given row can be resized by dragging with the mouse.
 
void DisableColResize (int col)
 Disable interactive resizing of the specified column.
 
void DisableRowResize (int row)
 Disable interactive resizing of the specified row.
 
void DisableDragColMove ()
 Disables column moving by dragging with the mouse.
 
void DisableDragColSize ()
 Disables column sizing by dragging with the mouse.
 
void DisableDragGridSize ()
 Disable mouse dragging of grid lines to resize rows and columns.
 
void DisableDragRowSize ()
 Disables row sizing by dragging with the mouse.
 
void EnableDragCell (bool enable=true)
 Enables or disables cell dragging with the mouse.
 
void EnableDragColMove (bool enable=true)
 Enables or disables column moving by dragging with the mouse.
 
void EnableDragColSize (bool enable=true)
 Enables or disables column sizing 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.
 
int GetColAt (int colPos) const
 Returns the column ID of the specified column position.
 
int GetColPos (int colID) const
 Returns the position of the specified column.
 
void SetColPos (int colID, int newPos)
 Sets the position of the specified column.
 
void SetColumnsOrder (const wxArrayInt &order)
 Sets the positions of all columns at once.
 
void ResetColPos ()
 Resets the position of the columns to the default.
 
Cursor Movement
int GetGridCursorCol () const
 Returns the current grid cell column position.
 
int GetGridCursorRow () const
 Returns the current grid cell row position.
 
void GoToCell (int row, int col)
 Make the given cell current and ensure it is visible.
 
void GoToCell (const wxGridCellCoords &coords)
 Make the given cell current and ensure it is visible.
 
bool MoveCursorDown (bool expandSelection)
 Moves the grid cursor down by one row.
 
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.
 
bool MoveCursorLeft (bool expandSelection)
 Moves the grid cursor left by one column.
 
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.
 
bool MoveCursorRight (bool expandSelection)
 Moves the grid cursor right by one column.
 
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.
 
bool MoveCursorUp (bool expandSelection)
 Moves the grid cursor up by one row.
 
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.
 
bool MovePageDown ()
 Moves the grid cursor down by some number of rows so that the previous bottom visible row becomes the top visible row.
 
bool MovePageUp ()
 Moves the grid cursor up by some number of rows so that the previous top visible row becomes the bottom visible row.
 
void SetGridCursor (int row, int col)
 Set the grid cursor to the specified cell.
 
void SetGridCursor (const wxGridCellCoords &coords)
 Set the grid cursor to the specified cell.
 
void SetTabBehaviour (TabBehaviour behaviour)
 Set the grid's behaviour when the user presses the TAB key.
 
User Selection
void ClearSelection ()
 Deselects all cells that are currently selected.
 
wxGridCellCoordsArray GetSelectedCells () const
 Returns an array of individually selected cells.
 
wxArrayInt GetSelectedCols () const
 Returns an array of selected columns.
 
wxArrayInt GetSelectedRows () const
 Returns an array of selected rows.
 
wxColour GetSelectionBackground () const
 Returns the colour used for drawing the selection background.
 
wxGridCellCoordsArray GetSelectionBlockBottomRight () const
 Returns an array of the bottom right corners of blocks of selected cells.
 
wxGridCellCoordsArray GetSelectionBlockTopLeft () const
 Returns an array of the top left corners of blocks of selected cells.
 
wxColour GetSelectionForeground () const
 Returns the colour used for drawing the selection foreground.
 
wxGridSelectionModes GetSelectionMode () const
 Returns the current selection mode.
 
bool IsInSelection (int row, int col) const
 Returns true if the given cell is selected.
 
bool IsInSelection (const wxGridCellCoords &coords) const
 Returns true if the given cell is selected.
 
bool IsSelection () const
 Returns true if there are currently any selected cells, rows, columns or blocks.
 
void SelectAll ()
 Selects all cells in the grid.
 
void SelectBlock (int topRow, int leftCol, int bottomRow, int rightCol, bool addToSelected=false)
 Selects a rectangular block of cells.
 
void SelectBlock (const wxGridCellCoords &topLeft, const wxGridCellCoords &bottomRight, bool addToSelected=false)
 Selects a rectangular block of cells.
 
void SelectCol (int col, bool addToSelected=false)
 Selects the specified column.
 
void SelectRow (int row, bool addToSelected=false)
 Selects the specified row.
 
void SetSelectionBackground (const wxColour &c)
 Set the colour to be used for drawing the selection background.
 
void SetSelectionForeground (const wxColour &c)
 Set the colour to be used for drawing the selection foreground.
 
void SetSelectionMode (wxGridSelectionModes selmode)
 Set the selection behaviour of the grid.
 
Scrolling
int GetScrollLineX () const
 Returns the number of pixels per horizontal scroll increment.
 
int GetScrollLineY () const
 Returns the number of pixels per vertical scroll increment.
 
bool IsVisible (int row, int col, bool wholeCellVisible=true) const
 Returns true if a cell is either entirely or at least partially visible in the grid window.
 
bool IsVisible (const wxGridCellCoords &coords, bool wholeCellVisible=true) const
 Returns true if a cell is either entirely or at least partially visible in the grid window.
 
void MakeCellVisible (int row, int col)
 Brings the specified cell into the visible grid cell area with minimal scrolling.
 
void MakeCellVisible (const wxGridCellCoords &coords)
 Brings the specified cell into the visible grid cell area with minimal scrolling.
 
void SetScrollLineX (int x)
 Sets the number of pixels per horizontal scroll increment.
 
void SetScrollLineY (int y)
 Sets the number of pixels per vertical scroll increment.
 
Cell and Device Coordinate Translation
wxRect BlockToDeviceRect (const wxGridCellCoords &topLeft, const wxGridCellCoords &bottomRight) const
 Convert grid cell coordinates to grid window pixel coordinates.
 
wxRect CellToRect (int row, int col) const
 Return the rectangle corresponding to the grid cell's size and position in logical coordinates.
 
wxRect CellToRect (const wxGridCellCoords &coords) const
 Return the rectangle corresponding to the grid cell's size and position in logical coordinates.
 
int XToCol (int x, bool clipToMinMax=false) const
 Returns the column at the given pixel position.
 
int XToEdgeOfCol (int x) const
 Returns the column whose right hand edge is close to the given logical x position.
 
wxGridCellCoords XYToCell (int x, int y) const
 Translates logical pixel coordinates to the grid cell coordinates.
 
wxGridCellCoords XYToCell (const wxPoint &pos) const
 Translates logical pixel coordinates to the grid cell coordinates.
 
int YToEdgeOfRow (int y) const
 Returns the row whose bottom edge is close to the given logical y position.
 
int YToRow (int y, bool clipToMinMax=false) const
 Returns the grid row that corresponds to the logical y coordinate.
 
Miscellaneous Functions
bool AppendCols (int numCols=1, bool updateLabels=true)
 Appends one or more new columns to the right of the grid.
 
bool AppendRows (int numRows=1, bool updateLabels=true)
 Appends one or more new rows to the bottom of the grid.
 
bool AreHorzGridLinesClipped () const
 Return true if the horizontal grid lines stop at the last column boundary or false if they continue to the end of the window.
 
bool AreVertGridLinesClipped () const
 Return true if the vertical grid lines stop at the last row boundary or false if they continue to the end of the window.
 
void BeginBatch ()
 Increments the grid's batch count.
 
void ClearGrid ()
 Clears all data in the underlying grid table and repaints the grid.
 
void ClipHorzGridLines (bool clip)
 Change whether the horizontal grid lines are clipped by the end of the last column.
 
void ClipVertGridLines (bool clip)
 Change whether the vertical grid lines are clipped by the end of the last row.
 
bool DeleteCols (int pos=0, int numCols=1, bool updateLabels=true)
 Deletes one or more columns from a grid starting at the specified position.
 
bool DeleteRows (int pos=0, int numRows=1, bool updateLabels=true)
 Deletes one or more rows from a grid starting at the specified position.
 
void EndBatch ()
 Decrements the grid's batch count.
 
virtual void Fit ()
 Overridden wxWindow method.
 
void ForceRefresh ()
 Causes immediate repainting of the grid.
 
int GetBatchCount ()
 Returns the number of times that BeginBatch() has been called without (yet) matching calls to EndBatch().
 
int GetNumberCols () const
 Returns the total number of grid columns.
 
int GetNumberRows () const
 Returns the total number of grid rows.
 
wxGridCellAttrGetOrCreateCellAttr (int row, int col) const
 Returns the attribute for the given cell creating one if necessary.
 
wxGridTableBaseGetTable () const
 Returns a base pointer to the current table object.
 
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.
 
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.
 
void RefreshAttr (int row, int col)
 Invalidates the cached attribute for the given cell.
 
void Render (wxDC &dc, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, const wxGridCellCoords &topLeft=wxGridCellCoords(-1,-1), const wxGridCellCoords &bottomRight=wxGridCellCoords(-1,-1), int style=wxGRID_DRAW_DEFAULT)
 Draws part or all of a wxGrid on a wxDC for printing or display.
 
void SetColAttr (int col, wxGridCellAttr *attr)
 Sets the cell attributes for all cells in the specified column.
 
void SetMargins (int extraWidth, int extraHeight)
 Sets the extra margins used around the grid area.
 
void SetRowAttr (int row, wxGridCellAttr *attr)
 Sets the cell attributes for all cells in the specified row.
 
wxArrayInt CalcRowLabelsExposed (const wxRegion &reg)
 Appends one or more new columns to the right of the grid.
 
wxArrayInt CalcColLabelsExposed (const wxRegion &reg)
 Appends one or more new columns to the right of the grid.
 
wxGridCellCoordsArray CalcCellsExposed (const wxRegion &reg)
 Appends one or more new columns to the right of the grid.
 
Sorting support.

wxGrid doesn't provide any support for sorting the data but it does generate events allowing the user code to sort it and supports displaying the sort indicator in the column used for sorting.

To use wxGrid sorting support you need to handle wxEVT_GRID_COL_SORT event (and not veto it) and resort the data displayed in the grid. The grid will automatically update the sorting indicator on the column which was clicked.

You can also call the functions in this section directly to update the sorting indicator. Once again, they don't do anything with the grid data, it remains your responsibility to actually sort it appropriately.

int GetSortingColumn () const
 Return the column in which the sorting indicator is currently displayed.
 
bool IsSortingBy (int col) const
 Return true if this column is currently used for sorting.
 
bool IsSortOrderAscending () const
 Return true if the current sorting order is ascending or false if it is descending.
 
void SetSortingColumn (int col, bool ascending=true)
 Set the column to display the sorting indicator in and its direction.
 
void UnsetSortingColumn ()
 Remove any currently shown sorting indicator.
 
Accessors for component windows.

Return the various child windows of wxGrid.

wxGrid is an empty parent window for 4 children representing the column labels window (top), the row labels window (left), the corner window (top left) and the main grid window. It may be necessary to use these individual windows and not the wxGrid window itself if you need to handle events for them (this can be done using wxEvtHandler::Connect() or wxWindow::PushEventHandler()) or do something else requiring the use of the correct window pointer. Notice that you should not, however, change these windows (e.g. reposition them or draw over them) because they are managed by wxGrid itself.

wxWindowGetGridWindow () const
 Return the main grid window containing the grid cells.
 
wxWindowGetGridRowLabelWindow () const
 Return the row labels window.
 
wxWindowGetGridColLabelWindow () const
 Return the column labels window.
 
wxWindowGetGridCornerLabelWindow () const
 Return the window in the top left grid corner.
 
wxHeaderCtrlGetGridColHeader () const
 Return the header control used for column labels display.
 
- Public Member Functions inherited from wxScrolled< T >
 wxScrolled ()
 Default constructor.
 
 wxScrolled (wxWindow *parent, wxWindowID id=-1, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxHSCROLL|wxVSCROLL, const wxString &name="scrolledWindow")
 Constructor.
 
void CalcScrolledPosition (int x, int y, int *xx, int *yy) const
 Translates the logical coordinates to the device ones.
 
wxPoint CalcScrolledPosition (const wxPoint &pt) const
 
void CalcUnscrolledPosition (int x, int y, int *xx, int *yy) const
 Translates the device coordinates to the logical ones.
 
wxPoint CalcUnscrolledPosition (const wxPoint &pt) const
 
bool Create (wxWindow *parent, wxWindowID id=-1, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxHSCROLL|wxVSCROLL, const wxString &name="scrolledWindow")
 Creates the window for two-step construction.
 
void DisableKeyboardScrolling ()
 Disable use of keyboard keys for scrolling.
 
void DoPrepareDC (wxDC &dc)
 Call this function to prepare the device context for drawing a scrolled image.
 
void EnableScrolling (bool xScrolling, bool yScrolling)
 Enable or disable use of wxWindow::ScrollWindow() for scrolling.
 
void ShowScrollbars (wxScrollbarVisibility horz, wxScrollbarVisibility vert)
 Set the scrollbar visibility.
 
void GetScrollPixelsPerUnit (int *xUnit, int *yUnit) const
 Get the number of pixels per scroll unit (line), in each direction, as set by SetScrollbars().
 
void GetViewStart (int *x, int *y) const
 Get the position at which the visible portion of the window starts.
 
wxPoint GetViewStart () const
 This is a simple overload of GetViewStart(int*,int*); see that function for more info.
 
void GetVirtualSize (int *x, int *y) const
 Gets the size in device units of the scrollable window area (as opposed to the client size, which is the area of the window currently visible).
 
bool IsRetained () const
 Motif only: true if the window has a backing bitmap.
 
virtual void OnDraw (wxDC &dc)
 Called by the default paint event handler to allow the application to define painting behaviour without having to worry about calling DoPrepareDC().
 
void PrepareDC (wxDC &dc)
 This function is for backwards compatibility only and simply calls DoPrepareDC() now.
 
void Scroll (int x, int y)
 Scrolls a window so the view start is at the given point.
 
void Scroll (const wxPoint &pt)
 This is an overload of Scroll(int,int); see that function for more info.
 
void SetScrollRate (int xstep, int ystep)
 Set the horizontal and vertical scrolling increment only.
 
void SetScrollbars (int pixelsPerUnitX, int pixelsPerUnitY, int noUnitsX, int noUnitsY, int xPos=0, int yPos=0, bool noRefresh=false)
 Sets up vertical and/or horizontal scrollbars.
 
void SetTargetWindow (wxWindow *window)
 Call this function to tell wxScrolled to perform the actual scrolling on a different window (and not on itself).
 
wxWindowGetTargetWindow () const
 
void SetTargetRect (const wxRect &rect)
 
wxRect GetTargetRect () const
 
int GetScrollPageSize (int orient) const
 
void SetScrollPageSize (int orient, int pageSize)
 
int GetScrollLines (int orient) const
 
void SetScale (double xs, double ys)
 
double GetScaleX () const
 
double GetScaleY () const
 
virtual void AdjustScrollbars ()
 
bool IsAutoScrolling () const
 Are we generating the autoscroll events?
 
void StopAutoScrolling ()
 Stop generating the scroll events when mouse is held outside the window.
 
virtual bool SendAutoScrollEvents (wxScrollWinEvent &event) const
 This method can be overridden in a derived class to forbid sending the auto scroll events - note that unlike StopAutoScrolling() it doesn't stop the timer, so it will be called repeatedly and will typically return different values depending on the current mouse position.
 

Protected Member Functions

bool CanHaveAttributes () const
 Returns true if this grid has support for cell attributes.
 
int GetColMinimalWidth (int col) const
 Get the minimal width of the given column/row.
 
int GetColRight (int col) const
 Returns the coordinate of the right border specified column.
 
int GetColLeft (int col) const
 Returns the coordinate of the left border specified column.
 
int GetRowMinimalHeight (int col) const
 Returns the minimal size for the given column.
 
- Protected Member Functions inherited from wxScrolled< T >
virtual wxSize GetSizeAvailableForScrollTarget (const wxSize &size)
 Function which must be overridden to implement the size available for the scroll target for the given size of the main window.
 

Member Enumeration Documentation

Return values for GetCellSize().

Since
2.9.1
Enumerator:
CellSpan_Inside 

This cell is inside a span covered by another cell.

CellSpan_None 

This is a normal, non-spanning cell.

CellSpan_Main 

This cell spans several physical wxGrid cells.

Constants defining different support built-in TAB handling behaviours.

The elements of this enum determine what happens when TAB is pressed when the cursor is in the rightmost column (or Shift-TAB is pressed when the cursor is in the leftmost one).

See Also
SetTabBehaviour(), wxEVT_GRID_TABBING
Since
2.9.5
Enumerator:
Tab_Stop 

Do nothing, this is default.

Tab_Wrap 

Move to the beginning of the next (or the end of the previous) row.

Tab_Leave 

Move to the next (or the previous) control after the grid.

Different selection modes supported by the grid.

Enumerator:
wxGridSelectCells 

The default selection mode allowing selection of the individual cells as well as of the entire rows and columns.

wxGridSelectRows 

The selection mode allowing the selection of the entire rows only.

The user won't be able to select any cells or columns in this mode.

wxGridSelectColumns 

The selection mode allowing the selection of the entire columns only.

The user won't be able to select any cells or rows in this mode.

wxGridSelectRowsOrColumns 

The selection mode allowing the user to select either the entire columns or the entire rows but not individual cells nor blocks.

Notice that while this constant is defined as

this doesn't mean that all the other combinations are valid – at least currently they are not.

Since
2.9.1

Constructor & Destructor Documentation

wxGrid::wxGrid ( )

Default constructor.

You must call Create() to really create the grid window and also call CreateGrid() or SetTable() to initialize the grid contents.

wxGrid::wxGrid ( wxWindow parent,
wxWindowID  id,
const wxPoint pos = wxDefaultPosition,
const wxSize size = wxDefaultSize,
long  style = wxWANTS_CHARS,
const wxString name = wxGridNameStr 
)

Constructor creating the grid window.

You must call either CreateGrid() or SetTable() to initialize the grid contents before using it.

virtual wxGrid::~wxGrid ( )
virtual

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 SetTable()).

Member Function Documentation

bool wxGrid::AppendCols ( int  numCols = 1,
bool  updateLabels = true 
)

Appends one or more new columns to the right of the grid.

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 InsertCols() for further information.

Returns
true on success or false if appending columns failed.
bool wxGrid::AppendRows ( int  numRows = 1,
bool  updateLabels = true 
)

Appends one or more new rows to the bottom of the grid.

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 InsertRows() for further information.

Returns
true on success or false if appending rows failed.
bool wxGrid::AreHorzGridLinesClipped ( ) const

Return true if the horizontal grid lines stop at the last column boundary or false if they continue to the end of the window.

The default is to clip grid lines.

See Also
ClipHorzGridLines(), AreVertGridLinesClipped()
bool wxGrid::AreVertGridLinesClipped ( ) const

Return true if the vertical grid lines stop at the last row boundary or false if they continue to the end of the window.

The default is to clip grid lines.

See Also
ClipVertGridLines(), AreHorzGridLinesClipped()
void wxGrid::AutoSize ( )

Automatically sets the height and width of all rows and columns to fit their contents.

void wxGrid::AutoSizeColLabelSize ( int  col)

Automatically adjusts width of the column to fit its label.

void wxGrid::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.

void wxGrid::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.

void wxGrid::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.

void wxGrid::AutoSizeRowLabelSize ( int  col)

Automatically adjusts height of the row to fit its label.

void wxGrid::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.

void wxGrid::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 EndBatch(). Code that does a lot of grid modification can be enclosed between BeginBatch() and EndBatch() calls to avoid screen flicker. The final EndBatch() call will cause the grid to be repainted.

Notice that you should use wxGridUpdateLocker which ensures that there is always a matching EndBatch() call for this BeginBatch() if possible instead of calling this method directly.

wxRect wxGrid::BlockToDeviceRect ( const wxGridCellCoords topLeft,
const wxGridCellCoords bottomRight 
) const

Convert grid cell coordinates to grid window pixel coordinates.

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.

See Also
CellToRect()
wxGridCellCoordsArray wxGrid::CalcCellsExposed ( const wxRegion reg)

Appends one or more new columns to the right of the grid.

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 InsertCols() for further information.

Returns
true on success or false if appending columns failed.
wxArrayInt wxGrid::CalcColLabelsExposed ( const wxRegion reg)

Appends one or more new columns to the right of the grid.

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 InsertCols() for further information.

Returns
true on success or false if appending columns failed.
wxArrayInt wxGrid::CalcRowLabelsExposed ( const wxRegion reg)

Appends one or more new columns to the right of the grid.

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 InsertCols() for further information.

Returns
true on success or false if appending columns failed.
bool wxGrid::CanDragCell ( ) const

Return true if the dragging of cells is enabled or false otherwise.

bool wxGrid::CanDragColMove ( ) const

Returns true if columns can be moved by dragging with the mouse.

Columns can be moved by dragging on their labels.

bool wxGrid::CanDragColSize ( int  col) const

Returns true if the given column can be resized by dragging with the mouse.

This function returns true if resizing the columns interactively is globally enabled, i.e. if DisableDragColSize() hadn't been called, and if this column wasn't explicitly marked as non-resizable with DisableColResize().

bool wxGrid::CanDragGridSize ( ) const

Return true if the dragging of grid lines to resize rows and columns is enabled or false otherwise.

bool wxGrid::CanDragRowSize ( int  row) const

Returns true if the given row can be resized by dragging with the mouse.

This is the same as CanDragColSize() but for rows.

bool wxGrid::CanEnableCellControl ( ) const

Returns true if the in-place edit control for the current grid cell can be used and false otherwise.

This function always returns false for the read-only cells.

bool wxGrid::CanHaveAttributes ( ) const
protected

Returns true if this grid has support for cell attributes.

The grid supports attributes if it has the associated table which, in turn, has attributes support, i.e. wxGridTableBase::CanHaveAttributes() returns true.

wxRect wxGrid::CellToRect ( int  row,
int  col 
) const

Return the rectangle corresponding to the grid cell's size and position in logical coordinates.

See Also
BlockToDeviceRect()
wxRect wxGrid::CellToRect ( const wxGridCellCoords coords) const

Return the rectangle corresponding to the grid cell's size and position in logical coordinates.

See Also
BlockToDeviceRect()
void wxGrid::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 wxGrid::ClearSelection ( )

Deselects all cells that are currently selected.

void wxGrid::ClipHorzGridLines ( bool  clip)

Change whether the horizontal grid lines are clipped by the end of the last column.

By default the grid lines are not drawn beyond the end of the last column but after calling this function with clip set to false they will be drawn across the entire grid window.

See Also
AreHorzGridLinesClipped(), ClipVertGridLines()
void wxGrid::ClipVertGridLines ( bool  clip)

Change whether the vertical grid lines are clipped by the end of the last row.

By default the grid lines are not drawn beyond the end of the last row but after calling this function with clip set to false they will be drawn across the entire grid window.

See Also
AreVertGridLinesClipped(), ClipHorzGridLines()
bool wxGrid::Create ( wxWindow parent,
wxWindowID  id,
const wxPoint pos = wxDefaultPosition,
const wxSize size = wxDefaultSize,
long  style = wxWANTS_CHARS,
const wxString name = wxGridNameStr 
)

Creates the grid window for an object initialized using the default constructor.

You must call either CreateGrid() or SetTable() to initialize the grid contents before using it.

bool wxGrid::CreateGrid ( int  numRows,
int  numCols,
wxGridSelectionModes  selmode = 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 SetTable().

bool wxGrid::DeleteCols ( int  pos = 0,
int  numCols = 1,
bool  updateLabels = true 
)

Deletes one or more columns from a grid starting at the specified position.

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 InsertCols() for further information.

Returns
true on success or false if deleting columns failed.
bool wxGrid::DeleteRows ( int  pos = 0,
int  numRows = 1,
bool  updateLabels = true 
)

Deletes one or more rows from a grid starting at the specified position.

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 InsertRows() for further information.

Returns
true on success or false if appending rows failed.
void wxGrid::DisableCellEditControl ( )

Disables in-place editing of grid cells.

Equivalent to calling EnableCellEditControl(false).

void wxGrid::DisableColResize ( int  col)

Disable interactive resizing of the specified column.

This method allows to disable resizing of an individual column in a grid where the columns are otherwise resizable (which is the case by default).

Notice that currently there is no way to make some columns resizable in a grid where columns can't be resized by default as there doesn't seem to be any need for this in practice. There is also no way to make the column marked as fixed using this method resizable again because it is supposed that fixed columns are used for static parts of the grid and so should remain fixed during the entire grid lifetime.

Also notice that disabling interactive column resizing will not prevent the program from changing the column size.

See Also
EnableDragColSize()
void wxGrid::DisableDragColMove ( )

Disables column moving by dragging with the mouse.

Equivalent to passing false to EnableDragColMove().

void wxGrid::DisableDragColSize ( )

Disables column sizing by dragging with the mouse.

Equivalent to passing false to EnableDragColSize().

void wxGrid::DisableDragGridSize ( )

Disable mouse dragging of grid lines to resize rows and columns.

Equivalent to passing false to EnableDragGridSize()

void wxGrid::DisableDragRowSize ( )

Disables row sizing by dragging with the mouse.

Equivalent to passing false to EnableDragRowSize().

void wxGrid::DisableRowResize ( int  row)

Disable interactive resizing of the specified row.

This is the same as DisableColResize() but for rows.

See Also
EnableDragRowSize()
virtual void wxGrid::DrawCellHighlight ( wxDC dc,
const wxGridCellAttr attr 
)
virtual
virtual void wxGrid::DrawColLabel ( wxDC dc,
int  col 
)
virtual
virtual void wxGrid::DrawColLabels ( wxDC dc,
const wxArrayInt cols 
)
virtual
virtual void wxGrid::DrawCornerLabel ( wxDC dc)
virtual
virtual void wxGrid::DrawRowLabel ( wxDC dc,
int  row 
)
virtual
virtual void wxGrid::DrawRowLabels ( wxDC dc,
const wxArrayInt rows 
)
virtual
void wxGrid::DrawTextRectangle ( wxDC dc,
const wxString text,
const wxRect rect,
int  horizontalAlignment = wxALIGN_LEFT,
int  verticalAlignment = wxALIGN_TOP,
int  textOrientation = wxHORIZONTAL 
) const
void wxGrid::DrawTextRectangle ( wxDC dc,
const wxArrayString lines,
const wxRect rect,
int  horizontalAlignment = wxALIGN_LEFT,
int  verticalAlignment = wxALIGN_TOP,
int  textOrientation = wxHORIZONTAL 
) const
void wxGrid::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 wxGrid::EnableDragCell ( bool  enable = true)

Enables or disables cell dragging with the mouse.

void wxGrid::EnableDragColMove ( bool  enable = true)

Enables or disables column moving by dragging with the mouse.

void wxGrid::EnableDragColSize ( bool  enable = true)

Enables or disables column sizing by dragging with the mouse.

See Also
DisableColResize()
void wxGrid::EnableDragGridSize ( bool  enable = true)

Enables or disables row and column resizing by dragging gridlines with the mouse.

void wxGrid::EnableDragRowSize ( bool  enable = true)

Enables or disables row sizing by dragging with the mouse.

See Also
DisableRowResize()
void wxGrid::EnableEditing ( bool  edit)

Makes the grid globally editable or read-only.

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 wxGridCellAttr::SetReadOnly(). For single cells you can also use the shortcut function SetReadOnly().

For more information about controlling grid cell attributes see the wxGridCellAttr class and the wxGrid Overview.

void wxGrid::EnableGridLines ( bool  enable = true)

Turns the drawing of grid lines on or off.

void wxGrid::EndBatch ( )

Decrements the grid's batch count.

When the count is greater than zero repainting of the grid is suppressed. Each previous call to 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.

See Also
wxGridUpdateLocker
virtual void wxGrid::Fit ( )
virtual

Overridden wxWindow method.

void wxGrid::ForceRefresh ( )

Causes immediate repainting of the grid.

Use this instead of the usual wxWindow::Refresh().

int wxGrid::GetBatchCount ( )

Returns the number of times that BeginBatch() has been called without (yet) matching calls to EndBatch().

While the grid's batch count is greater than zero the display will not be updated.

void wxGrid::GetCellAlignment ( int  row,
int  col,
int *  horiz,
int *  vert 
) const

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 wxGrid::GetCellBackgroundColour ( int  row,
int  col 
) const

Returns the background colour of the cell at the specified location.

wxGridCellEditor* wxGrid::GetCellEditor ( int  row,
int  col 
) const

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.

The caller must call DecRef() on the returned pointer.

wxFont wxGrid::GetCellFont ( int  row,
int  col 
) const

Returns the font for text in the grid cell at the specified location.

wxColour wxGrid::GetCellHighlightColour ( ) const
int wxGrid::GetCellHighlightPenWidth ( ) const
int wxGrid::GetCellHighlightROPenWidth ( ) const
bool wxGrid::GetCellOverflow ( int  row,
int  col 
) const

Returns true if the cell value can overflow.

A cell can overflow if the next cell in the row is empty.

wxGridCellRenderer* wxGrid::GetCellRenderer ( int  row,
int  col 
) const

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.

The caller must call DecRef() on the returned pointer.

CellSpan wxGrid::GetCellSize ( int  row,
int  col,
int *  num_rows,
int *  num_cols 
) const

Get the size of the cell in number of cells covered by it.

For normal cells, the function fills both num_rows and num_cols with 1 and returns CellSpan_None. For cells which span multiple cells, i.e. for which SetCellSize() had been called, the returned values are the same ones as were passed to SetCellSize() call and the function return value is CellSpan_Main.

More unexpectedly, perhaps, the returned values may be negative for the cells which are inside a span covered by a cell occupying multiple rows or columns. They correspond to the offset of the main cell of the span from the cell passed to this functions and the function returns CellSpan_Inside value to indicate this.

As an example, consider a 3*3 grid with the cell (1, 1) (the one in the middle) having a span of 2 rows and 2 columns, i.e. the grid looks like

+----+----+----+
| | | |
+----+----+----+
| | |
+----+ |
| | |
+----+----+----+

Then the function returns 2 and 2 in num_rows and num_cols for the cell (1, 1) itself and -1 and -1 for the cell (2, 2) as well as -1 and 0 for the cell (2, 1).

Parameters
rowThe row of the cell.
colThe column of the cell.
num_rowsPointer to variable receiving the number of rows, must not be NULL.
num_colsPointer to variable receiving the number of columns, must not be NULL.
Returns
The kind of this cell span (the return value is new in wxWidgets 2.9.1, this function was void in previous wxWidgets versions).
wxSize wxGrid::GetCellSize ( const wxGridCellCoords coords)

Get the number of rows and columns allocated for this cell.

This overload doesn't return a CellSpan value but the values returned may still be negative, see GetCellSize(int, int, int *, int *) for details.

wxColour wxGrid::GetCellTextColour ( int  row,
int  col 
) const

Returns the text colour for the grid cell at the specified location.

wxString wxGrid::GetCellValue ( int  row,
int  col 
) const

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 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.

wxString wxGrid::GetCellValue ( const wxGridCellCoords coords) const

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 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 wxGrid::GetColAt ( int  colPos) const

Returns the column ID of the specified column position.

virtual wxPen wxGrid::GetColGridLinePen ( int  col)
virtual

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.

void wxGrid::GetColLabelAlignment ( int *  horiz,
int *  vert 
) const

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 wxGrid::GetColLabelSize ( ) const

Returns the current height of the column labels.

int wxGrid::GetColLabelTextOrientation ( ) const

Returns the orientation of the column labels (either wxHORIZONTAL or wxVERTICAL).

wxString wxGrid::GetColLabelValue ( int  col) const

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 wxGrid::GetColLeft ( int  col) const
protected

Returns the coordinate of the left border specified column.

int wxGrid::GetColMinimalAcceptableWidth ( ) const

Returns the minimal width to which a column may be resized.

Use SetColMinimalAcceptableWidth() to change this value globally or SetColMinimalWidth() to do it for individual columns.

See Also
GetRowMinimalAcceptableHeight()
int wxGrid::GetColMinimalWidth ( int  col) const
protected

Get the minimal width of the given column/row.

The value returned by this function may be different than that returned by GetColMinimalAcceptableWidth() if SetColMinimalWidth() had been called for this column.

int wxGrid::GetColPos ( int  colID) const

Returns the position of the specified column.

int wxGrid::GetColRight ( int  col) const
protected

Returns the coordinate of the right border specified column.

int wxGrid::GetColSize ( int  col) const

Returns the width of the specified column.

wxGridSizesInfo wxGrid::GetColSizes ( ) const

Get size information for all columns at once.

This method is useful when the information about all column widths needs to be saved. The widths can be later restored using SetColSizes().

See Also
wxGridSizesInfo, GetRowSizes()
void wxGrid::GetDefaultCellAlignment ( int *  horiz,
int *  vert 
) const

Returns the default cell alignment.

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.

See Also
SetDefaultCellAlignment()
wxColour wxGrid::GetDefaultCellBackgroundColour ( ) const

Returns the current default background colour for grid cells.

wxFont wxGrid::GetDefaultCellFont ( ) const

Returns the current default font for grid cell text.

bool wxGrid::GetDefaultCellOverflow ( ) const

Returns true if the cells can overflow by default.

wxColour wxGrid::GetDefaultCellTextColour ( ) const

Returns the current default colour for grid cell text.

int wxGrid::GetDefaultColLabelSize ( ) const

Returns the default height for column labels.

int wxGrid::GetDefaultColSize ( ) const

Returns the current default width for grid columns.

wxGridCellEditor* wxGrid::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.

virtual wxGridCellEditor* wxGrid::GetDefaultEditorForCell ( int  row,
int  col 
) const
virtual

Returns the default editor for the specified cell.

The base class version returns the editor appropriate for the current cell type but this method may be overridden in the derived classes to use custom editors for some cells by default.

Notice that the same may be achieved in a usually simpler way by associating a custom editor with the given cell or cells.

The caller must call DecRef() on the returned pointer.

wxGridCellEditor* wxGrid::GetDefaultEditorForCell ( const wxGridCellCoords c) const

Returns the default editor for the specified cell.

The base class version returns the editor appropriate for the current cell type but this method may be overridden in the derived classes to use custom editors for some cells by default.

Notice that the same may be achieved in a usually simpler way by associating a custom editor with the given cell or cells.

The caller must call DecRef() on the returned pointer.

virtual wxGridCellEditor* wxGrid::GetDefaultEditorForType ( const wxString typeName) const
virtual

Returns the default editor for the cells containing values of the given type.

The base class version returns the editor which was associated with the specified typeName when it was registered RegisterDataType() but this function may be overridden to return something different. This allows to override an editor used for one of the standard types.

The caller must call DecRef() on the returned pointer.

virtual wxPen wxGrid::GetDefaultGridLinePen ( )
virtual

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()
wxGridCellRenderer* wxGrid::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.

The caller must call DecRef() on the returned pointer.

virtual wxGridCellRenderer* wxGrid::GetDefaultRendererForCell ( int  row,
int  col 
) const
virtual

Returns the default renderer for the given cell.

The base class version returns the renderer appropriate for the current cell type but this method may be overridden in the derived classes to use custom renderers for some cells by default.

The caller must call DecRef() on the returned pointer.

virtual wxGridCellRenderer* wxGrid::GetDefaultRendererForType ( const wxString typeName) const
virtual

Returns the default renderer for the cell containing values of the given type.

See Also
GetDefaultEditorForType()
int wxGrid::GetDefaultRowLabelSize ( ) const

Returns the default width for the row labels.

int wxGrid::GetDefaultRowSize ( ) const

Returns the current default height for grid rows.

wxHeaderCtrl* wxGrid::GetGridColHeader ( ) const

Return the header control used for column labels display.

This function can only be called if UseNativeColHeader() had been called.

wxWindow* wxGrid::GetGridColLabelWindow ( ) const

Return the column labels window.

This window is not shown if the columns labels were hidden using HideColLabels().

Depending on whether UseNativeColHeader() was called or not this can be either a wxHeaderCtrl or a plain wxWindow. This function returns a valid window pointer in either case but in the former case you can also use GetGridColHeader() to access it if you need wxHeaderCtrl-specific functionality.

wxWindow* wxGrid::GetGridCornerLabelWindow ( ) const

Return the window in the top left grid corner.

This window is shown only of both columns and row labels are shown and normally doesn't contain anything. Clicking on it is handled by wxGrid however and can be used to select the entire grid.

int wxGrid::GetGridCursorCol ( ) const

Returns the current grid cell column position.

int wxGrid::GetGridCursorRow ( ) const

Returns the current grid cell row position.

wxColour wxGrid::GetGridLineColour ( ) const

Returns the colour used for grid lines.

See Also
GetDefaultGridLinePen()
wxWindow* wxGrid::GetGridRowLabelWindow ( ) const

Return the row labels window.

This window is not shown if the row labels were hidden using HideRowLabels().

wxWindow* wxGrid::GetGridWindow ( ) const

Return the main grid window containing the grid cells.

This window is always shown.

wxColour wxGrid::GetLabelBackgroundColour ( ) const

Returns the colour used for the background of row and column labels.

wxFont wxGrid::GetLabelFont ( ) const

Returns the font used for row and column labels.

wxColour wxGrid::GetLabelTextColour ( ) const

Returns the colour used for row and column label text.

int wxGrid::GetNumberCols ( ) const

Returns the total number of grid columns.

This is the same as the number of columns in the underlying grid table.

int wxGrid::GetNumberRows ( ) const

Returns the total number of grid rows.

This is the same as the number of rows in the underlying grid table.

wxGridCellAttr* wxGrid::GetOrCreateCellAttr ( int  row,
int  col 
) const

Returns the attribute for the given cell creating one if necessary.

If the cell already has an attribute, it is returned. Otherwise a new attribute is created, associated with the cell and returned. In any case the caller must call DecRef() on the returned pointer.

This function may only be called if CanHaveAttributes() returns true.

virtual wxPen wxGrid::GetRowGridLinePen ( int  row)
virtual

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.

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
}
void wxGrid::GetRowLabelAlignment ( int *  horiz,
int *  vert 
) const

Returns the alignment used for row labels.

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 wxGrid::GetRowLabelSize ( ) const

Returns the current width of the row labels.

wxString wxGrid::GetRowLabelValue ( int  row) const

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 wxGrid::GetRowMinimalAcceptableHeight ( ) const

Returns the minimal size to which rows can be resized.

Use SetRowMinimalAcceptableHeight() to change this value globally or SetRowMinimalHeight() to do it for individual cells.

See Also
GetColMinimalAcceptableWidth()
int wxGrid::GetRowMinimalHeight ( int  col) const
protected

Returns the minimal size for the given column.

The value returned by this function may be different than that returned by GetRowMinimalAcceptableHeight() if SetRowMinimalHeight() had been called for this row.

int wxGrid::GetRowSize ( int  row) const

Returns the height of the specified row.

wxGridSizesInfo wxGrid::GetRowSizes ( ) const

Get size information for all row at once.

See Also
wxGridSizesInfo, GetColSizes()
int wxGrid::GetScrollLineX ( ) const

Returns the number of pixels per horizontal scroll increment.

The default is 15.

See Also
GetScrollLineY(), SetScrollLineX(), SetScrollLineY()
int wxGrid::GetScrollLineY ( ) const

Returns the number of pixels per vertical scroll increment.

The default is 15.

See Also
GetScrollLineX(), SetScrollLineX(), SetScrollLineY()
wxGridCellCoordsArray wxGrid::GetSelectedCells ( ) const

Returns an array of individually selected cells.

Notice that this array does not contain all the selected cells in general as it doesn't include the cells selected as part of column, row or block selection. You must use this method, GetSelectedCols(), GetSelectedRows() and GetSelectionBlockTopLeft() and GetSelectionBlockBottomRight() methods to obtain the entire selection in general.

Please notice this behaviour is by design and is needed in order to support grids of arbitrary size (when an entire column is selected in a grid with a million of columns, we don't want to create an array with a million of entries in this function, instead it returns an empty array and GetSelectedCols() returns an array containing one element).

wxArrayInt wxGrid::GetSelectedCols ( ) const

Returns an array of selected columns.

Please notice that this method alone is not sufficient to find all the selected columns as it contains only the columns which were individually selected but not those being part of the block selection or being selected in virtue of all of their cells being selected individually, please see GetSelectedCells() for more details.

wxArrayInt wxGrid::GetSelectedRows ( ) const

Returns an array of selected rows.

Please notice that this method alone is not sufficient to find all the selected rows as it contains only the rows which were individually selected but not those being part of the block selection or being selected in virtue of all of their cells being selected individually, please see GetSelectedCells() for more details.

wxColour wxGrid::GetSelectionBackground ( ) const

Returns the colour used for drawing the selection background.

wxGridCellCoordsArray wxGrid::GetSelectionBlockBottomRight ( ) const

Returns an array of the bottom right corners of blocks of selected cells.

Please see GetSelectedCells() for more information about the selection representation in wxGrid.

See Also
GetSelectionBlockTopLeft()
wxGridCellCoordsArray wxGrid::GetSelectionBlockTopLeft ( ) const

Returns an array of the top left corners of blocks of selected cells.

Please see GetSelectedCells() for more information about the selection representation in wxGrid.

See Also
GetSelectionBlockBottomRight()
wxColour wxGrid::GetSelectionForeground ( ) const

Returns the colour used for drawing the selection foreground.

wxGridSelectionModes wxGrid::GetSelectionMode ( ) const

Returns the current selection mode.

See Also
SetSelectionMode().
int wxGrid::GetSortingColumn ( ) const

Return the column in which the sorting indicator is currently displayed.

Returns wxNOT_FOUND if sorting indicator is not currently displayed at all.

See Also
SetSortingColumn()
wxGridTableBase* wxGrid::GetTable ( ) const

Returns a base pointer to the current table object.

The returned pointer is still owned by the grid.

void wxGrid::GoToCell ( int  row,
int  col 
)

Make the given cell current and ensure it is visible.

This method is equivalent to calling MakeCellVisible() and SetGridCursor() and so, as with the latter, a wxEVT_GRID_SELECT_CELL event is generated by it and the selected cell doesn't change if the event is vetoed.

void wxGrid::GoToCell ( const wxGridCellCoords coords)

Make the given cell current and ensure it is visible.

This method is equivalent to calling MakeCellVisible() and SetGridCursor() and so, as with the latter, a wxEVT_GRID_SELECT_CELL event is generated by it and the selected cell doesn't change if the event is vetoed.

bool wxGrid::GridLinesEnabled ( ) const

Returns true if drawing of grid lines is turned on, false otherwise.

void wxGrid::HideCellEditControl ( )

Hides the in-place cell edit control.

void wxGrid::HideCol ( int  col)

Hides the specified column.

To show the column later you need to call SetColSize() with non-0 width or ShowCol() to restore the previous column width.

If the column is already hidden, this method doesn't do anything.

Parameters
colThe column index.
void wxGrid::HideColLabels ( )

Hides the column labels by calling SetColLabelSize() with a size of 0.

Show labels again by calling that method with a width greater than 0.

void wxGrid::HideRow ( int  col)

Hides the specified row.

To show the row later you need to call SetRowSize() with non-0 width or ShowRow() to restore its original height.

If the row is already hidden, this method doesn't do anything.

Parameters
colThe row index.
void wxGrid::HideRowLabels ( )

Hides the row labels by calling SetRowLabelSize() with a size of 0.

The labels can be shown again by calling SetRowLabelSize() with a width greater than 0.

bool wxGrid::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.

Notice that inserting the columns in the grid requires grid table cooperation: when this method is called, grid object begins by 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 CreateGrid()) this process is automatic. If you are using a custom grid table (specified with SetTable()) then you must override wxGridTableBase::InsertCols() in your derived table class.

Parameters
posThe position which the first newly inserted column will have.
numColsThe number of columns to insert.
updateLabelsCurrently not used.
Returns
true if the columns were successfully inserted, false if an error occurred (most likely the table couldn't be updated).
bool wxGrid::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.

Notice that you must implement wxGridTableBase::InsertRows() if you use a grid with a custom table, please see InsertCols() for more information.

Parameters
posThe position which the first newly inserted row will have.
numRowsThe number of rows to insert.
updateLabelsCurrently not used.
Returns
true if the rows were successfully inserted, false if an error occurred (most likely the table couldn't be updated).
bool wxGrid::IsCellEditControlEnabled ( ) const

Returns true if the in-place edit control is currently enabled.

bool wxGrid::IsColShown ( int  col) const

Returns true if the specified column is not currently hidden.

bool wxGrid::IsCurrentCellReadOnly ( ) const

Returns true if the current cell is read-only.

See Also
SetReadOnly(), IsReadOnly()
bool wxGrid::IsEditable ( ) const

Returns false if the whole grid has been set as read-only or true otherwise.

See EnableEditing() for more information about controlling the editing status of grid cells.

bool wxGrid::IsInSelection ( int  row,
int  col 
) const

Returns true if the given cell is selected.

bool wxGrid::IsInSelection ( const wxGridCellCoords coords) const

Returns true if the given cell is selected.

bool wxGrid::IsReadOnly ( int  row,
int  col 
) const

Returns true if the cell at the specified location can't be edited.

See Also
SetReadOnly(), IsCurrentCellReadOnly()
bool wxGrid::IsRowShown ( int  row) const

Returns true if the specified row is not currently hidden.

bool wxGrid::IsSelection ( ) const

Returns true if there are currently any selected cells, rows, columns or blocks.

bool wxGrid::IsSortingBy ( int  col) const

Return true if this column is currently used for sorting.

See Also
GetSortingColumn()
bool wxGrid::IsSortOrderAscending ( ) const

Return true if the current sorting order is ascending or false if it is descending.

It only makes sense to call this function if GetSortingColumn() returns a valid column index and not wxNOT_FOUND.

See Also
SetSortingColumn()
bool wxGrid::IsVisible ( int  row,
int  col,
bool  wholeCellVisible = true 
) const

Returns true if a cell is either entirely or at least partially visible in the grid window.

By default, the cell must be entirely visible for this function to return true but if wholeCellVisible is false, the function returns true even if the cell is only partially visible.

bool wxGrid::IsVisible ( const wxGridCellCoords coords,
bool  wholeCellVisible = true 
) const

Returns true if a cell is either entirely or at least partially visible in the grid window.

By default, the cell must be entirely visible for this function to return true but if wholeCellVisible is false, the function returns true even if the cell is only partially visible.

void wxGrid::MakeCellVisible ( int  row,
int  col 
)

Brings the specified cell into the visible grid cell area with minimal scrolling.

Does nothing if the cell is already visible.

void wxGrid::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 wxGrid::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.

bool wxGrid::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.

bool wxGrid::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.

bool wxGrid::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.

bool wxGrid::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.

bool wxGrid::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.

bool wxGrid::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.

bool wxGrid::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.

bool wxGrid::MovePageDown ( )

Moves the grid cursor down by some number of rows so that the previous bottom visible row becomes the top visible row.

bool wxGrid::MovePageUp ( )

Moves the grid cursor up by some number of rows so that the previous top visible row becomes the bottom visible row.

bool wxGrid::ProcessTableMessage ( wxGridTableMessage msg)

Receive and handle a message from the table.

void wxGrid::RefreshAttr ( int  row,
int  col 
)

Invalidates the cached attribute for the given cell.

For efficiency reasons, wxGrid may cache the recently used attributes (currently it caches only the single most recently used one, in fact) which can result in the cell appearance not being refreshed even when the attribute returned by your custom wxGridCellAttrProvider-derived class has changed. To force the grid to refresh the cell attribute, this function may be used. Notice that calling it will not result in actually redrawing the cell, you still need to call wxWindow::RefreshRect() to invalidate the area occupied by the cell in the window to do this. Also note that you don't need to call this function if you store the attributes in wxGrid itself, i.e. use its SetAttr() and similar methods, it is only useful when using a separate custom attributes provider.

Parameters
rowThe row of the cell whose attribute needs to be queried again.
colThe column of the cell whose attribute needs to be queried again.
Since
2.9.2
void wxGrid::RegisterDataType ( const wxString typeName,
wxGridCellRenderer renderer,
wxGridCellEditor editor 
)

Register a new data type.

The data types allow to naturally associate specific renderers and editors to the cells containing values of the given type. For example, the grid automatically registers a data type with the name wxGRID_VALUE_STRING which uses wxGridCellStringRenderer and wxGridCellTextEditor as its renderer and editor respectively – this is the data type used by all the cells of the default wxGridStringTable, so this renderer and editor are used by default for all grid cells.

However if a custom table returns wxGRID_VALUE_BOOL from its wxGridTableBase::GetTypeName() method, then wxGridCellBoolRenderer and wxGridCellBoolEditor are used for it because the grid also registers a boolean data type with this name.

And as this mechanism is completely generic, you may register your own data types using your own custom renderers and editors. Just remember that the table must identify a cell as being of the given type for them to be used for this cell.

Parameters
typeNameName of the new type. May be any string, but if the type name is the same as the name of an already registered type, including one of the standard ones (which are wxGRID_VALUE_STRING, wxGRID_VALUE_BOOL, wxGRID_VALUE_NUMBER, wxGRID_VALUE_FLOAT and wxGRID_VALUE_CHOICE), then the new registration information replaces the previously used renderer and editor.
rendererThe renderer to use for the cells of this type. Its ownership is taken by the grid, i.e. it will call DecRef() on this pointer when it doesn't need it any longer.
editorThe editor to use for the cells of this type. Its ownership is also taken by the grid.
void wxGrid::Render ( wxDC dc,
const wxPoint pos = wxDefaultPosition,
const wxSize size = wxDefaultSize,
const wxGridCellCoords topLeft = wxGridCellCoords(-1,-1),
const wxGridCellCoords bottomRight = wxGridCellCoords(-1,-1),
int  style = wxGRID_DRAW_DEFAULT 
)

Draws part or all of a wxGrid on a wxDC for printing or display.

Pagination can be accomplished by using sequential Render() calls with appropriate values in wxGridCellCoords topLeft and bottomRight.

Parameters
dcThe wxDC to be drawn on.
posThe position on the wxDC where rendering should begin. If not specified drawing will begin at the wxDC MaxX() and MaxY().
sizeThe size of the area on the wxDC that the rendered wxGrid should occupy. If not specified the drawing will be scaled to fit the available dc width or height. The wxGrid's aspect ratio is maintained whether or not size is specified.
topLeftThe top left cell of the block to be drawn. Defaults to ( 0, 0 ).
bottomRightThe bottom right cell of the block to be drawn. Defaults to row and column counts.
styleA combination of values from wxGridRenderStyle.
Since
2.9.4
void wxGrid::ResetColPos ( )

Resets the position of the columns to the default.

void wxGrid::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 wxGrid::SelectAll ( )

Selects all cells in the grid.

void wxGrid::SelectBlock ( int  topRow,
int  leftCol,
int  bottomRow,
int  rightCol,
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 wxGrid::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 wxGrid::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.

This method won't select anything if the current selection mode is wxGridSelectRows.

void wxGrid::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.

This method won't select anything if the current selection mode is wxGridSelectColumns.

void wxGrid::SetCellAlignment ( int  row,
int  col,
int  horiz,
int  vert 
)

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 wxGrid::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.

Deprecated:
Please use SetCellAlignment(row, col, horiz, vert) instead.
void wxGrid::SetCellBackgroundColour ( int  row,
int  col,
const wxColour colour 
)

Set the background colour for the given cell or all cells by default.

void wxGrid::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 wxGrid::SetCellFont ( int  row,
int  col,
const wxFont font 
)

Sets the font for text in the grid cell at the specified location.

void wxGrid::SetCellHighlightColour ( const wxColour )
void wxGrid::SetCellHighlightPenWidth ( int  width)
void wxGrid::SetCellHighlightROPenWidth ( int  width)
void wxGrid::SetCellOverflow ( int  row,
int  col,
bool  allow 
)

Sets the overflow permission of the cell.

void wxGrid::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 wxGrid::SetCellSize ( int  row,
int  col,
int  num_rows,
int  num_cols 
)

Set the size of the cell.

Specifying a value of more than 1 in num_rows or num_cols will make the cell at (row, col) span the block of the specified size, covering the other cells which would be normally shown in it. Passing 1 for both arguments resets the cell to normal appearance.

See Also
GetCellSize()
Parameters
rowThe row of the cell.
colThe column of the cell.
num_rowsNumber of rows to be occupied by this cell, must be >= 1.
num_colsNumber of columns to be occupied by this cell, must be >= 1.
void wxGrid::SetCellTextColour ( int  row,
int  col,
const wxColour colour 
)

Sets the text colour for the given cell.

void wxGrid::SetCellTextColour ( const wxColour val,
int  row,
int  col 
)

Sets the text colour for the given cell.

Deprecated:
Please use SetCellTextColour(row, col, colour)
void wxGrid::SetCellTextColour ( const wxColour colour)

Sets the text colour for all cells by default.

Deprecated:
Please use SetDefaultCellTextColour(colour) instead.
void wxGrid::SetCellValue ( int  row,
int  col,
const wxString s 
)

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 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.

See wxGridTableBase::CanSetValueAs() and the wxGrid Overview for more information.

void wxGrid::SetCellValue ( const wxGridCellCoords coords,
const wxString s 
)

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 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.

See wxGridTableBase::CanSetValueAs() and the wxGrid Overview for more information.

void wxGrid::SetCellValue ( const wxString val,
int  row,
int  col 
)
Deprecated:
Please use SetCellValue(int,int,const wxString&) or SetCellValue(const wxGridCellCoords&,const wxString&) instead.

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 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.

See wxGridTableBase::CanSetValueAs() and the wxGrid Overview for more information.

void wxGrid::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 Overview.

void wxGrid::SetColFormatBool ( int  col)

Sets the specified column to display boolean values.

See Also
SetColFormatCustom()
void wxGrid::SetColFormatCustom ( int  col,
const wxString typeName 
)

Sets the specified column to display data in a custom format.

This method provides an alternative to defining a custom grid table which would return typeName from its GetTypeName() method for the cells in this column: while it doesn't really change the type of the cells in this column, it does associate the renderer and editor used for the cells of the specified type with them.

See the wxGrid Overview for more information on working with custom data types.

void wxGrid::SetColFormatFloat ( int  col,
int  width = -1,
int  precision = -1 
)

Sets the specified column to display floating point values with the given width and precision.

See Also
SetColFormatCustom()
void wxGrid::SetColFormatNumber ( int  col)

Sets the specified column to display integer values.

See Also
SetColFormatCustom()
void wxGrid::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 wxGrid::SetColLabelSize ( int  height)

Sets the height of the column labels.

If height equals to wxGRID_AUTOSIZE then height is calculated automatically so that no label is truncated. Note that this could be slow for a large table.

void wxGrid::SetColLabelTextOrientation ( int  textOrientation)

Sets the orientation of the column labels (either wxHORIZONTAL or wxVERTICAL).

void wxGrid::SetColLabelValue ( int  col,
const wxString value 
)

Set the value for the given column label.

If you are using a custom grid table you must override wxGridTableBase::SetColLabelValue() for this to have any effect.

void wxGrid::SetColMinimalAcceptableWidth ( int  width)

Sets the minimal width to which the user can resize columns.

See Also
GetColMinimalAcceptableWidth()
void wxGrid::SetColMinimalWidth ( int  col,
int  width 
)

Sets the minimal width for the specified column col.

It is usually best to call this method during grid creation as calling it later will not resize the column to the given minimal width even if it is currently narrower than it.

width must be greater than the minimal acceptable column width as returned by GetColMinimalAcceptableWidth().

void wxGrid::SetColPos ( int  colID,
int  newPos 
)

Sets the position of the specified column.

void wxGrid::SetColSize ( int  col,
int  width 
)

Sets the width of the specified column.

Parameters
colThe column index.
widthThe new column width in pixels, 0 to hide the column or -1 to fit the column width to its label width.
void wxGrid::SetColSizes ( const wxGridSizesInfo sizeInfo)

Restore all columns sizes.

This is usually called with wxGridSizesInfo object previously returned by GetColSizes().

See Also
SetRowSizes()
void wxGrid::SetColumnsOrder ( const wxArrayInt order)

Sets the positions of all columns at once.

This method takes an array containing the indices of the columns in their display order, i.e. uses the same convention as wxHeaderCtrl::SetColumnsOrder().

void wxGrid::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 wxGrid::SetDefaultCellBackgroundColour ( const wxColour colour)

Sets the default background colour for grid cells.

void wxGrid::SetDefaultCellFont ( const wxFont font)

Sets the default font to be used for grid cell text.

void wxGrid::SetDefaultCellOverflow ( bool  allow)

Sets the default overflow permission of the cells.

void wxGrid::SetDefaultCellTextColour ( const wxColour colour)

Sets the current default colour for grid cell text.

void wxGrid::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.

If width is less than GetColMinimalAcceptableWidth(), then the minimal acceptable width is used instead of it.

void wxGrid::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 wxGrid::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 wxGrid::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.

If height is less than GetRowMinimalAcceptableHeight(), then the minimal acceptable height is used instead of it.

void wxGrid::SetGridCursor ( int  row,
int  col 
)

Set the grid cursor to the specified cell.

The grid cursor indicates the current cell and can be moved by the user using the arrow keys or the mouse.

Calling this function generates a wxEVT_GRID_SELECT_CELL event and if the event handler vetoes this event, the cursor is not moved.

This function doesn't make the target call visible, use GoToCell() to do this.

void wxGrid::SetGridCursor ( const wxGridCellCoords coords)

Set the grid cursor to the specified cell.

The grid cursor indicates the current cell and can be moved by the user using the arrow keys or the mouse.

Calling this function generates a wxEVT_GRID_SELECT_CELL event and if the event handler vetoes this event, the cursor is not moved.

This function doesn't make the target call visible, use GoToCell() to do this.

void wxGrid::SetGridLineColour ( const wxColour colour)

Sets the colour used to draw grid lines.

void wxGrid::SetLabelBackgroundColour ( const wxColour colour)

Sets the background colour for row and column labels.

void wxGrid::SetLabelFont ( const wxFont font)

Sets the font for row and column labels.

void wxGrid::SetLabelTextColour ( const wxColour colour)

Sets the colour for row and column label text.

void wxGrid::SetMargins ( int  extraWidth,
int  extraHeight 
)

Sets the extra margins used around the grid area.

A grid may occupy more space than needed for its data display and this function allows to set how big this extra space is

void wxGrid::SetReadOnly ( int  row,
int  col,
bool  isReadOnly = true 
)

Makes the cell at the specified location read-only or editable.

See Also
IsReadOnly()
void wxGrid::SetRowAttr ( int  row,
wxGridCellAttr attr 
)

Sets the cell attributes for all cells in the specified row.

The grid takes ownership of the attribute pointer.

See the wxGridCellAttr class for more information about controlling cell attributes.

void wxGrid::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 wxGrid::SetRowLabelSize ( int  width)

Sets the width of the row labels.

If width equals wxGRID_AUTOSIZE then width is calculated automatically so that no label is truncated. Note that this could be slow for a large table.

void wxGrid::SetRowLabelValue ( int  row,
const wxString value 
)

Sets 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 wxGrid::SetRowMinimalAcceptableHeight ( int  height)

Sets the minimal row height used by default.

See SetColMinimalAcceptableWidth() for more information.

void wxGrid::SetRowMinimalHeight ( int  row,
int  height 
)

Sets the minimal height for the specified row.

See SetColMinimalWidth() for more information.

void wxGrid::SetRowSize ( int  row,
int  height 
)

Sets the height of the specified row.

See SetColSize() for more information.

void wxGrid::SetRowSizes ( const wxGridSizesInfo sizeInfo)

Restore all rows sizes.

See Also
SetColSizes()
void wxGrid::SetScrollLineX ( int  x)

Sets the number of pixels per horizontal scroll increment.

The default is 15.

See Also
GetScrollLineX(), GetScrollLineY(), SetScrollLineY()
void wxGrid::SetScrollLineY ( int  y)

Sets the number of pixels per vertical scroll increment.

The default is 15.

See Also
GetScrollLineX(), GetScrollLineY(), SetScrollLineX()
void wxGrid::SetSelectionBackground ( const wxColour c)

Set the colour to be used for drawing the selection background.

void wxGrid::SetSelectionForeground ( const wxColour c)

Set the colour to be used for drawing the selection foreground.

void wxGrid::SetSelectionMode ( wxGridSelectionModes  selmode)

Set the selection behaviour of the grid.

The existing selection is converted to conform to the new mode if possible and discarded otherwise (e.g. any individual selected cells are deselected if the new mode allows only the selection of the entire rows or columns).

void wxGrid::SetSortingColumn ( int  col,
bool  ascending = true 
)

Set the column to display the sorting indicator in and its direction.

Parameters
colThe column to display the sorting indicator in or wxNOT_FOUND to remove any currently displayed sorting indicator.
ascendingIf true, display the ascending sort indicator, otherwise display the descending sort indicator.
See Also
GetSortingColumn(), IsSortOrderAscending()
void wxGrid::SetTabBehaviour ( TabBehaviour  behaviour)

Set the grid's behaviour when the user presses the TAB key.

Pressing the TAB key moves the grid cursor right in the current row, if there is a cell at the right and, similarly, Shift-TAB moves the cursor to the left in the current row if it's not in the first column.

What happens if the cursor can't be moved because it it's already at the beginning or end of the row can be configured using this function, see wxGrid::TabBehaviour documentation for the detailed description.

IF none of the standard behaviours is appropriate, you can always handle wxEVT_GRID_TABBING event directly to implement a custom TAB-handling logic.

Since
2.9.5
bool wxGrid::SetTable ( wxGridTableBase table,
bool  takeOwnership = false,
wxGridSelectionModes  selmode = 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 CreateGrid() when your application involves complex or non-string data or data sets that are too large to fit wholly in memory.

void wxGrid::SetUseNativeColLabels ( bool  native = true)

Call this in order to make the column labels use a native look by using wxRendererNative::DrawHeaderButton() internally.

There is no equivalent method for drawing row columns as there is not native look for that. This option is useful when using wxGrid for displaying tables and not as a spread-sheet.

See Also
UseNativeColHeader()
void wxGrid::ShowCellEditControl ( )

Displays the in-place cell edit control for the current cell.

void wxGrid::ShowCol ( int  col)

Shows the previously hidden column by resizing it to non-0 size.

The column is shown again with the same width that it had before HideCol() call.

If the column is currently shown, this method doesn't do anything.

See Also
HideCol(), SetColSize()
void wxGrid::ShowRow ( int  col)

Shows the previously hidden row.

The row is shown again with the same height that it had before HideRow() call.

If the row is currently shown, this method doesn't do anything.

See Also
HideRow(), SetRowSize()
void wxGrid::UnsetSortingColumn ( )

Remove any currently shown sorting indicator.

This is equivalent to calling SetSortingColumn() with wxNOT_FOUND first argument.

void wxGrid::UseNativeColHeader ( bool  native = true)

Enable the use of native header window for column labels.

If this function is called with true argument, a wxHeaderCtrl is used instead to display the column labels instead of drawing them in wxGrid code itself. This has the advantage of making the grid look and feel perfectly the same as native applications (using SetUseNativeColLabels() the grid can be made to look more natively but it still doesn't feel natively, notably the column resizing and dragging still works slightly differently as it is implemented in wxWidgets itself) but results in different behaviour for column and row headers, for which there is no equivalent function, and, most importantly, is unsuitable for grids with huge numbers of columns as wxHeaderCtrl doesn't support virtual mode. Because of this, by default the grid does not use the native header control but you should call this function to enable it if you are using the grid to display tabular data and don't have thousands of columns in it.

Another difference between the default behaviour and the native header behaviour is that the latter provides the user with a context menu (which appears on right clicking the header) allowing to rearrange the grid columns if CanDragColMove() returns true. If you want to prevent this from happening for some reason, you need to define a handler for wxEVT_GRID_LABEL_RIGHT_CLICK event which simply does nothing (in particular doesn't skip the event) as this will prevent the default right click handling from working.

Also note that currently wxEVT_GRID_LABEL_RIGHT_DCLICK event is not generated for the column labels if the native columns header is used (but this limitation could possibly be lifted in the future).

int wxGrid::XToCol ( int  x,
bool  clipToMinMax = false 
) const

Returns the column at the given pixel position.

Parameters
xThe x position to evaluate.
clipToMinMaxIf true, rather than returning wxNOT_FOUND, it returns either the first or last column depending on whether x is too far to the left or right respectively.
Returns
The column index or wxNOT_FOUND.
int wxGrid::XToEdgeOfCol ( int  x) const

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.

wxGridCellCoords wxGrid::XYToCell ( int  x,
int  y 
) const

Translates logical pixel coordinates to the grid cell coordinates.

Notice that this function expects logical coordinates on input so if you use this function in a mouse event handler you need to translate the mouse position, which is expressed in device coordinates, to logical ones.

See Also
XToCol(), YToRow()
wxGridCellCoords wxGrid::XYToCell ( const wxPoint pos) const

Translates logical pixel coordinates to the grid cell coordinates.

Notice that this function expects logical coordinates on input so if you use this function in a mouse event handler you need to translate the mouse position, which is expressed in device coordinates, to logical ones.

See Also
XToCol(), YToRow()
int wxGrid::YToEdgeOfRow ( int  y) const

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 wxGrid::YToRow ( int  y,
bool  clipToMinMax = false 
) const

Returns the grid row that corresponds to the logical y coordinate.

Returns wxNOT_FOUND if there is no row at the y position.