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
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
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.
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.
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.
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.
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.
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.
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)
bool CurrentCellVisible()
Returns TRUE if the currently selected cell is visible, FALSE otherwise.
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.
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.
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.
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.
wxGridCell * GetCell(int row, int col) const
Returns the grid cell object associated with this position.
wxGenericGrid implementation only.
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() |
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() |
wxGridCell *** GetCells() const
Returns the array of grid cell object associated with this wxGrid.
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() |
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() |
wxString& GetCellValue(int row, int col) const
Returns the cell value at the given position.
int GetCols() const
Returns the number of columns in the grid.
int GetColumnWidth(int col) const
Gets the width in pixels for column col.
wxRectangle * GetCurrentRect() const
Returns a pointer to the rectangle enclosing the currently selected cell. Do not delete this pointer.
int GetCursorColumn() const
Returns the column position of the currently selected cell.
int GetCursorRow() const
Returns the row position of the currently selected cell.
bool GetEditable() const
Returns TRUE if the grid cells can be edited.
bool GetEditInPlace() const
Returns TRUE if editing in-place is enabled.
wxScrollBar * GetHorizScrollBar() const
Returns a pointer to the horizontal scrollbar.
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.
wxColour& GetLabelBackgroundColour() const
Gets a row and column label text colour.
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.
wxColour& GetLabelTextColour() const
Gets a row and column label text colour.
wxFont& GetLabelTextFont() const
Gets the font to be used for the row and column labels.
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.
int GetRowHeight(int row) const
Gets the height in pixels for row row.
int GetRows() const
Returns the number of rows in the grid.
int GetScrollPosX() const
Returns the column scroll position.
int GetScrollPosY() const
Returns the row scroll position.
wxTextCtrl * GetTextItem() const
Returns a pointer to the text item used for entering text into a cell.
wxScrollBar * GetVertScrollBar() const
Returns a pointer to the vertical scrollbar.
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.
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.
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.
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.
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.
wxGridCell * OnCreateCell()
Override this virtual function if you want to replace the normal wxGridCell with a derived class.
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.
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.
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.
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.
void OnSelectCell(int row, int col)
Virtual function called when the user left-clicks on a cell.
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.
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) |
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) |
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) |
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) |
void SetCellValue(const wxString& val, int row, int col)
Sets the cell value at the given position.
void SetColumnWidth(int col, int width)
Sets the width in pixels for column col.
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.
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.
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.
void SetGridCursor(int row, int col)
Sets the position of the selected cell.
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.
void SetLabelBackgroundColour(const wxColour& value)
Sets a row or column label background colour.
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.
void SetLabelTextColour(const wxColour& value)
Sets a row and column label text colour.
void SetLabelTextFont(const wxFont& font)
Sets the font to be used for the row and column labels.
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.
void SetRowHeight(int row, int height)
Sets the height in pixels for row row.
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.