## wxGrid

wxGrid is a class for displaying and editing tabular information.

Note: there is a new grid implementation from wxWindows 2.1.14, with an API that is backwardly compatible with the one documented here. This documentation is awaiting updates for the new and improved API.

Derived from

wxPanel
wxWindow
wxEvtHandler
wxObject

Include files

<wx/grid.h>

Window styles

There are no specific window styles for this class, but you may use different SetXXX() functions to change the controls behaviour (for example, to enable in-place editing).

See also window styles overview.

See also

wxGrid classes overview

Members

wxGrid::wxGrid
wxGrid::AdjustScrollbars
wxGrid::AppendCols
wxGrid::AppendRows
wxGrid::BeginBatch
wxGrid::CellHitTest
wxGrid::CreateGrid
wxGrid::CurrentCellVisible
wxGrid::DeleteCols
wxGrid::DeleteRows
wxGrid::EndBatch
wxGrid::GetBatchCount
wxGrid::GetCell
wxGrid::GetCellAlignment
wxGrid::GetCellBackgroundColour
wxGrid::GetCells
wxGrid::GetCellTextColour
wxGrid::GetCellTextFont
wxGrid::GetCellValue
wxGrid::GetCols
wxGrid::GetColumnWidth
wxGrid::GetCurrentRect
wxGrid::GetCursorColumn
wxGrid::GetCursorRow
wxGrid::GetEditable
wxGrid::GetEditInPlace
wxGrid::GetHorizScrollBar
wxGrid::GetLabelAlignment
wxGrid::GetLabelBackgroundColour
wxGrid::GetLabelSize
wxGrid::GetLabelTextColour
wxGrid::GetLabelTextFont
wxGrid::GetLabelValue
wxGrid::GetRowHeight
wxGrid::GetRows
wxGrid::GetScrollPosX
wxGrid::GetScrollPosY
wxGrid::GetTextItem
wxGrid::GetVertScrollBar
wxGrid::InsertCols
wxGrid::InsertRows
wxGrid::OnActivate
wxGrid::OnChangeLabels
wxGrid::OnChangeSelectionLabel
wxGrid::OnCreateCell
wxGrid::OnCellLeftClick
wxGrid::OnCellRightClick
wxGrid::OnLabelLeftClick
wxGrid::OnLabelRightClick
wxGrid::OnSelectCell
wxGrid::OnSelectCellImplementation
wxGrid::SetCellAlignment
wxGrid::SetCellBackgroundColour
wxGrid::SetCellTextColour
wxGrid::SetCellTextFont
wxGrid::SetCellValue
wxGrid::SetColumnWidth
wxGrid::SetDividerPen
wxGrid::SetEditable
wxGrid::SetEditInPlace
wxGrid::SetGridCursor
wxGrid::SetLabelAlignment
wxGrid::SetLabelBackgroundColour
wxGrid::SetLabelSize
wxGrid::SetLabelTextColour
wxGrid::SetLabelTextFont
wxGrid::SetLabelValue
wxGrid::SetRowHeight
wxGrid::UpdateDimensions

### wxGrid::wxGrid

void wxGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style=0, const wxString& name="grid")

Constructor. Before using a wxGrid object, you must call CreateGrid to set up the required rows and columns.

### wxGrid::AdjustScrollbars

void AdjustScrollbars()

Call this function whenever a change has been made via the API that might alter the scrollbar characteristics: particularly when adding or deleting rows, or changing row or column dimensions. For example, removing rows might make it unnecessary to show the vertical scrollbar.

### wxGrid::AppendCols

bool AppendCols(int n=1, bool updateLabels=TRUE)

Appends n columns to the grid. If updateLabels is TRUE, the function OnChangeLabels is called to give the application the opportunity to relabel.

### wxGrid::AppendRows

bool AppendRows(int n=1, bool updateLabels=TRUE)

Appends n rows to the grid. If updateLabels is TRUE, the function OnChangeLabels is called to give the application the opportunity to relabel.

### wxGrid::BeginBatch

void BeginBatch()

Start a BeginBatch/EndBatch pair between which, calls to SetCellValue or SetCellBitmap will not cause a refresh. This allows you to speed up some operations (for example, setting several hundred cell values). You can nest, but not overlap, these two functions.

See also wxGrid::EndBatch, wxGrid::GetBatchCount.

### wxGrid::CellHitTest

bool CellHitTest(int x, int y, int *row, int *col)

Returns TRUE if the x, y panel position coincides with a cell. If so, row and col are returned.

### wxGrid::CreateGrid

bool CreateGrid(int rows, int cols, wxString **cellValues=NULL, short *widths=NULL, short defaultWidth=wxGRID_DEFAULT_CELL_WIDTH, short defaultHeight=wxGRID_DEFAULT_CELL_HEIGHT)

Creates a grid rows high and cols wide. You can optionally specify an array of initial values and widths, and/or default cell width and height.

Call this function after creating the wxGrid object.

wxPython note: Currently the `cellValues` and `widths` parameters don't exisit in the wxPython version of this method. So in other words, the definition of the wxPython version of this method looks like this:

        CreateGrid(rows, cols,
                   defaultWidth = wxGRID_DEFAULT_CELL_WIDTH,
                   defaultHeight = wxGRID_DEFAULT_CELL_HEIGHT)

### wxGrid::CurrentCellVisible

bool CurrentCellVisible()

Returns TRUE if the currently selected cell is visible, FALSE otherwise.

### wxGrid::DeleteCols

bool DeleteCols(int pos=0, int n=1, bool updateLabels=TRUE)

Deletes n columns from the grid at position pos. If updateLabels is TRUE, the function OnChangeLabels is called to give the application the opportunity to relabel.

### wxGrid::DeleteRows

bool DeleteRows(int pos=0, int n=1, bool updateLabels=TRUE)

Deletes n rows from the grid at position pos. If updateLabels is TRUE, the function OnChangeLabels is called to give the application the opportunity to relabel.

### wxGrid::EndBatch

void EndBatch()

End a BeginBatch/EndBatch pair between which, calls to SetCellValue or SetCellBitmap will not cause a refresh. This allows you to speed up some operations (for example, setting several hundred cell values). You can nest, but not overlap, these two functions.

See also wxGrid::BeginBatch, wxGrid::GetBatchCount.

### wxGrid::GetBatchCount

int GetBatchCount() const

Return the level of batch nesting. This is initially zero, and will be incremented every time BeginBatch is called, and decremented when EndBatch is called. When the batch count is more zero, some functions (such as SetCellValue and SetCellBitmap) will not refresh the cell.

See also wxGrid::BeginBatch, wxGrid::EndBatch.

### wxGrid::GetCell

wxGridCell * GetCell(int row, int col) const

Returns the grid cell object associated with this position.

wxGenericGrid implementation only.

### wxGrid::GetCellAlignment

int GetCellAlignment(int row, int col) const

int GetCellAlignment() const

Sets the text alignment for the cell at the given position, or the global alignment value. The return value is wxLEFT, wxRIGHT or wxCENTRE.

wxPython note: In place of a single overloaded method name, wxPython implements the following methods:

GetCellAlignment(row, col) |
GetDefCellAlignment() |

### wxGrid::GetCellBackgroundColour

wxColour& GetCellBackgroundColour(int row, int col) const

wxColour& GetCellBackgroundColour() const

Gets the background colour for the cell at the given position, or the global background colour.

wxPython note: In place of a single overloaded method name, wxPython implements the following methods:

GetCellBackgroundColour(row, col) |
GetDefCellBackgroundColourt() |

### wxGrid::GetCells

wxGridCell *** GetCells() const

Returns the array of grid cell object associated with this wxGrid.

### wxGrid::GetCellTextColour

wxColour& GetCellTextColour(int row, int col) const

wxColour& GetCellTextColour() const

Gets the text colour for the cell at the given position, or the global text colour.

wxPython note: In place of a single overloaded method name, wxPython implements the following methods:

GetCellTextColour(row, col) |
GetDefCellTextColour() |

### wxGrid::GetCellTextFont

const wxFont& GetCellTextFont(int row, int col) const

wxFont& GetCellTextFont() const

Gets the text font for the cell at the given position, or the global text font.

wxPython note: In place of a single overloaded method name, wxPython implements the following methods:

GetCellTextFont(row, col) |
GetDefCellTextFont() |

### wxGrid::GetCellValue

wxString& GetCellValue(int row, int col) const

Returns the cell value at the given position.

### wxGrid::GetCols

int GetCols() const

Returns the number of columns in the grid.

### wxGrid::GetColumnWidth

int GetColumnWidth(int col) const

Gets the width in pixels for column col.

### wxGrid::GetCurrentRect

wxRectangle * GetCurrentRect() const

Returns a pointer to the rectangle enclosing the currently selected cell. Do not delete this pointer.

### wxGrid::GetCursorColumn

int GetCursorColumn() const

Returns the column position of the currently selected cell.

### wxGrid::GetCursorRow

int GetCursorRow() const

Returns the row position of the currently selected cell.

### wxGrid::GetEditable

bool GetEditable() const

Returns TRUE if the grid cells can be edited.

### wxGrid::GetEditInPlace

bool GetEditInPlace() const

Returns TRUE if editing in-place is enabled.

### wxGrid::GetHorizScrollBar

wxScrollBar * GetHorizScrollBar() const

Returns a pointer to the horizontal scrollbar.

### wxGrid::GetLabelAlignment

int GetLabelAlignment(int orientation) const

Gets the row or column label alignment. orientation should be wxHORIZONTAL to specify column label, wxVERTICAL to specify row label. alignment should be wxCENTRE, wxLEFT or wxRIGHT.

### wxGrid::GetLabelBackgroundColour

wxColour& GetLabelBackgroundColour() const

Gets a row and column label text colour.

### wxGrid::GetLabelSize

int GetLabelSize(int orientation) const

Gets the row label height, or column label width, in pixels. orientation should be wxHORIZONTAL to specify column label, wxVERTICAL to specify row label.

### wxGrid::GetLabelTextColour

wxColour& GetLabelTextColour() const

Gets a row and column label text colour.

### wxGrid::GetLabelTextFont

wxFont& GetLabelTextFont() const

Gets the font to be used for the row and column labels.

### wxGrid::GetLabelValue

wxString& GetLabelValue(int orientation, int pos) const

Gets a row or column label value. orientation should be wxHORIZONTAL to specify column label, wxVERTICAL to specify row label. pos is the label position.

### wxGrid::GetRowHeight

int GetRowHeight(int row) const

Gets the height in pixels for row row.

### wxGrid::GetRows

int GetRows() const

Returns the number of rows in the grid.

### wxGrid::GetScrollPosX

int GetScrollPosX() const

Returns the column scroll position.

### wxGrid::GetScrollPosY

int GetScrollPosY() const

Returns the row scroll position.

### wxGrid::GetTextItem

wxTextCtrl * GetTextItem() const

Returns a pointer to the text item used for entering text into a cell.

### wxGrid::GetVertScrollBar

wxScrollBar * GetVertScrollBar() const

Returns a pointer to the vertical scrollbar.

### wxGrid::InsertCols

bool InsertCols(int pos=0, int n=1, bool updateLabels=TRUE)

Inserts n number of columns before position pos. If updateLabels is TRUE, the function OnChangeLabels is called to give the application the opportunity to relabel.

### wxGrid::InsertRows

bool InsertRows(int pos=0, int n=1, bool updateLabels=TRUE)

Inserts n number of rows before position pos. If updateLabels is TRUE, the function OnChangeLabels is called to give the application the opportunity to relabel.

### wxGrid::OnActivate

void OnActivate(bool active)

Sets the text item to have the focus. Call this function when the wxGrid window should have the focus, for example from wxFrame::OnActivate.

### wxGrid::OnChangeLabels

void OnChangeLabels()

Called when rows and columns are created or deleted, to allow the application an opportunity to update the labels. By default, columns are labelled alphabetically, and rows numerically.

### wxGrid::OnChangeSelectionLabel

void OnChangeSelectionLabel()

Called when a cell is selected, to allow the application an opportunity to update the selection label (the label of the wxTextCtrl used for entering cell text). By default, the cell column letter and row number are concatenated to form the selection label.

### wxGrid::OnCreateCell

wxGridCell * OnCreateCell()

Override this virtual function if you want to replace the normal wxGridCell with a derived class.

### wxGrid::OnCellLeftClick

void OnLeftClick(int row, int col, int x, int y, bool control, bool shift)

Virtual function called when the left button is depressed within a cell, just after OnSelectCell is called.

### wxGrid::OnCellRightClick

void OnRightClick(int row, int col, int x, int y, bool control, bool shift)

Virtual function called when the right button is depressed within a cell, just after OnSelectCell is called.

### wxGrid::OnLabelLeftClick

void OnLeftClick(int row, int col, int x, int y, bool control, bool shift)

Virtual function called when the left button is depressed within a label.

row will be -1 if the click is in the top labels.

col will be -1 if the click is in the left labels.

row and col will be -1 if the click is in the upper left corner.

### wxGrid::OnLabelRightClick

void OnRightClick(int row, int col, int x, int y, bool control, bool shift)

Virtual function called when the right button is depressed within a label.

row will be -1 if the click is in the top labels.

col will be -1 if the click is in the left labels.

row and col will be -1 if the click is in the upper left corner.

### wxGrid::OnSelectCell

void OnSelectCell(int row, int col)

Virtual function called when the user left-clicks on a cell.

### wxGrid::OnSelectCellImplementation

void OnSelectCellImplementation(wxDC *dc, int row, int col)

Virtual function called when the user left-clicks on a cell. If you override this function, call wxGrid::OnSelectCell to apply the default behaviour.

### wxGrid::SetCellAlignment

void SetCellAlignment(int alignment, int row, int col)

void SetCellAlignment(int alignment)

Sets the text alignment for the cell at the given position, or for the whole grid. alignment may be wxLEFT, wxRIGHT or wxCENTRE.

wxPython note: In place of a single overloaded method name, wxPython implements the following methods:

SetCellAlignment(alignment, row, col) |
SetDefCellAlignment(alignment) |

### wxGrid::SetCellBackgroundColour

void SetCellBackgroundColour(const wxColour& colour, int row, int col)

void SetCellBackgroundColour(const wxColour& colour)

Sets the background colour for the cell at the given position, or for the whole grid.

wxPython note: In place of a single overloaded method name, wxPython implements the following methods:

SetCellBackgroundColour(colour, row, col) |
SetDefCellBackgroundColour(colour) |

### wxGrid::SetCellTextColour

void SetCellTextColour(const wxColour& colour, int row, int col)

void SetCellTextColour(const wxColour& colour)

Sets the text colour for the cell at the given position, or for the whole grid.

wxPython note: In place of a single overloaded method name, wxPython implements the following methods:

SetCellTextColour(colour, row, col) |
SetDefCellTextColour(colour) |

### wxGrid::SetCellTextFont

void SetCellTextFont(const wxFont& font, int row, int col)

void SetCellTextFont(const wxFont& font)

Sets the text font for the cell at the given position, or for the whole grid.

wxPython note: In place of a single overloaded method name, wxPython implements the following methods:

SetCellTextFont(font, row, col) |
SetDefCellTextFont(font) |

### wxGrid::SetCellValue

void SetCellValue(const wxString& val, int row, int col)

Sets the cell value at the given position.

### wxGrid::SetColumnWidth

void SetColumnWidth(int col, int width)

Sets the width in pixels for column col.

### wxGrid::SetDividerPen

void SetDividerPen(const wxPen& pen)

Specifies the pen to be used for drawing the divisions between cells. The default is a light grey. If NULL is specified, the divisions will not be drawn.

### wxGrid::SetEditable

void SetEditable(bool editable)

If editable is TRUE (the default), the grid cells will be editable by means of the text edit control. If FALSE, the text edit control will be hidden and the user will not be able to edit the cell contents.

### wxGrid::SetEditInPlace

void SetEditInPlace(bool edit = TRUE)

Enables (if edit is TRUE, default value) or disables in-place editing. When it is enabled, the cells contents can be changed by typing text directly in the cell.

### wxGrid::SetGridCursor

void SetGridCursor(int row, int col)

Sets the position of the selected cell.

### wxGrid::SetLabelAlignment

void SetLabelAlignment(int orientation, int alignment)

Sets the row or column label alignment. orientation should be wxHORIZONTAL to specify column label, wxVERTICAL to specify row label. alignment should be wxCENTRE, wxLEFT or wxRIGHT.

### wxGrid::SetLabelBackgroundColour

void SetLabelBackgroundColour(const wxColour& value)

Sets a row or column label background colour.

### wxGrid::SetLabelSize

void SetLabelSize(int orientation, int size)

Sets the row label height, or column label width, in pixels. orientation should be wxHORIZONTAL to specify column label, wxVERTICAL to specify row label.

If a dimension of zero is specified, the row or column labels will not be shown.

### wxGrid::SetLabelTextColour

void SetLabelTextColour(const wxColour& value)

Sets a row and column label text colour.

### wxGrid::SetLabelTextFont

void SetLabelTextFont(const wxFont& font)

Sets the font to be used for the row and column labels.

### wxGrid::SetLabelValue

void SetLabelValue(int orientation, const wxString& value, int pos)

Sets a row or column label value. orientation should be wxHORIZONTAL to specify column label, wxVERTICAL to specify row label. pos is the label position.

### wxGrid::SetRowHeight

void SetRowHeight(int row, int height)

Sets the height in pixels for row row.

### wxGrid::UpdateDimensions

void UpdateDimensions()

Call this function whenever a change has been made via the API that might alter size characteristics. You may also need to follow it with a call to AdjustScrollbars.