wxRuby Documentation Home

# Wx::GridTableBase

GridTableBase is an advanced way of supplying data to the cells in a
Grid. It is particularly useful for working with very large
grids, and for closely connecting the Grid display with an underlying
data source such as a SQL database. It can make for more efficient and
cleaner code.

In a standard Grid, the size of the grid is specified using
Grid#create_table, and then the contents of
each cell specified using
Grid#set_value. Whilst this is this is
straightforward for smaller grids, with very large grids it may become
inefficient and slow to set all the values when only a small proportion
are actually shown to the user at any one time. If the data source is,
for example, a SQL database, the GUI event handling code in the grid,
and the code to fetch and set rows in the database can become mixed up
in the Grid class.

GridTableBase is a class which can supply, on
demand, cell values and visual appearance attributes as particular cells
are displayed in a Grid.

To use this class, you must derive your own Ruby class from it, and
implement at set of methods to return the grid’s size, cell values, and
visual attributes. Then, instead of calling “Grid#create_table” on the
grid to set its size, call “Grid#set_table” and pass in an instance of
your GridTableBase subclass.

### Presenting data

The number of methods that have to be defined in a subclass of
GridTableBase will depend on the interactions that are permitted by the
Grid class it will be associated with. The minimal set of
methods that must be implemented in a read-only grid is:

- get_number_cols
- get_number_rows
- get_value
- is_empty_cell
- get_attr

In addition, you may wish to override:

- get_row_label_value
- get_col_label_value

### Data types, cell renderers and cell editors

In order to use custom GridCellRenderers or
GridCellEditors for particular cells, you will
need first to define the grid’s data types using
Grid#register_data_type. This will
link appropriate cell renderers and editors to particular named data
types. Then, your GridTableBase class should override the following
method to return the type name for each cell in the table:

- get_type_name

Note that you must not try to provide custom editors or renderers to
specific cells by associating them with the GridCellAttr returned by the
get_attr method of your Table class.

### Handling cell edits

In order for a user to be able to edit values within the grid, you must
also override:

- set_value

This will be called when the user finishes editing a cell’s value; it is
up to your class to decide how to respond (for example, storing the
value back in a database). Further methods will need to be provided if
the user is permitted to add or delete columns and rows.

## Derived from

Object

## Methods

- GridTableBase.new
- GridTableBase#get_number_rows
- GridTableBase#get_number_cols
- GridTableBase#is_empty_cell
- GridTableBase#get_value
- GridTableBase#set_value
- GridTableBase#get_type_name
- GridTableBase#can_get_value_as
- GridTableBase#can_set_value_as
- GridTableBase#get_value_as_long
- GridTableBase#get_value_as_double
- GridTableBase#get_value_as_bool
- GridTableBase#set_value_as_long
- GridTableBase#set_value_as_double
- GridTableBase#set_value_as_bool
- GridTableBase#get_value_as_custom
- GridTableBase#set_value_as_custom
- GridTableBase#set_view
- GridTableBase#get_view
- GridTableBase#clear
- GridTableBase#insert_rows
- GridTableBase#append_rows
- GridTableBase#delete_rows
- GridTableBase#insert_cols
- GridTableBase#append_cols
- GridTableBase#delete_cols
- GridTableBase#get_row_label_value
- GridTableBase#get_col_label_value
- GridTableBase#set_row_label_value
- GridTableBase#set_col_label_value
- GridTableBase#update_attr_rows
- GridTableBase#update_attr_cols
- GridTableBase#get_attr
- GridTableBase#set_attr
- GridTableBase#set_row_attr
- GridTableBase#set_col_attr

### GridTableBase.new

Creates a new GridTable. If you define your own `initialize` function in
your subclass of GridTableBase, you must ensure you call `super` within
that constructor.

### GridTableBase#get_number_rows

Integer get_number_rows()

Should return the total number of rows in the grid. You must override these
functions in a derived table class.

### GridTableBase#get_number_cols

Integer get_number_cols()

Should return the total number of columns in the grid. You must override
this functions in a derived table class.

### GridTableBase#is_empty_cell

Boolean is_empty_cell(%(arg-type)Integer% row, Integer col)

Should return true if a cell is empty. You must override this function
in a derived table class.

### GridTableBase#get_value

String get_value(%(arg-type)Integer% row, Integer col)

Should return the content of the specified cell as a Ruby string. You
must override this function in a derived table class.

### GridTableBase#set_value

set_value(%(arg-type)Integer% row, Integer col, String value)

Called when the value of a cell is updated by the user.

### GridTableBase#get_type_name

String get_type_name(%(arg-type)Integer% row, Integer col)

This method should return the name of the data type in the given
cell. This is useful to enable different custom cell renderers and
editors to be used for different cells in the grid.The name should match
one that has previously been set in the grid using
Grid#register_data_type.

### GridTableBase#can_get_value_as

Boolean can_get_value_as(%(arg-type)Integer% row, Integer col, String typeName)

### GridTableBase#can_set_value_as

Boolean can_set_value_as(%(arg-type)Integer% row, Integer col, String typeName)

### GridTableBase#get_value_as_long

Integer get_value_as_long(%(arg-type)Integer% row, Integer col)

### GridTableBase#get_value_as_double

double get_value_as_double(%(arg-type)Integer% row, Integer col)

### GridTableBase#get_value_as_bool

Boolean get_value_as_bool(%(arg-type)Integer% row, Integer col)

### GridTableBase#set_value_as_long

set_value_as_long(%(arg-type)Integer% row, Integer col, Integer value)

### GridTableBase#set_value_as_double

set_value_as_double(%(arg-type)Integer% row, Integer col, Float value)

### GridTableBase#set_value_as_bool

set_value_as_bool(%(arg-type)Integer% row, Integer col, Boolean value)

### GridTableBase#get_value_as_custom

get_value_as_custom(%(arg-type)Integer% row, Integer col, String typeName)

For user defined types

### GridTableBase#set_value_as_custom

set_value_as_custom(%(arg-type)Integer% row, Integer col, String typeName, (arg-type) value)

### GridTableBase#set_view

set_view(%(arg-type)Grid% grid)

Overriding these is optional

### GridTableBase#get_view

Grid get_view()

### GridTableBase#clear

clear()

### GridTableBase#insert_rows

Boolean insert_rows(%(arg-type)Integer% pos = 0, Integer numRows = 1)

### GridTableBase#append_rows

Boolean append_rows(%(arg-type)Integer% numRows = 1)

### GridTableBase#delete_rows

Boolean delete_rows(%(arg-type)Integer% pos = 0, Integer numRows = 1)

### GridTableBase#insert_cols

Boolean insert_cols(%(arg-type)Integer% pos = 0, Integer numCols = 1)

### GridTableBase#append_cols

Boolean append_cols(%(arg-type)Integer% numCols = 1)

### GridTableBase#delete_cols

Boolean delete_cols(%(arg-type)Integer% pos = 0, Integer numCols = 1)

### GridTableBase#get_row_label_value

String get_row_label_value(%(arg-type)Integer% row)

### GridTableBase#get_col_label_value

String get_col_label_value(%(arg-type)Integer% col)

### GridTableBase#set_row_label_value

set_row_label_value(%(arg-type)Integer% (row), String label)

### GridTableBase#set_col_label_value

set_col_label_value(%(arg-type)Integer% col, String label)

Handle setting the column label.

### GridTableBase#update_attr_rows

update_attr_rows(%(arg-type)Integer% pos, Integer numRows)

Change row/col number in attribute if needed

### GridTableBase#update_attr_cols

update_attr_cols(%(arg-type)Integer% pos, Integer numCols)

### GridTableBase#get_attr

GridCellAttr get_attr(%(arg-type)Integer% row, Integer col, Integer attr_kind)

Should return a grid cell attribute that should be
applied to the cell specified by row and column_. This can set the
cell’s text and background colour. However, it should not associate an
editor or renderer with a cell; instead use
get_type_namegettypename to link data types to
specific presentations.

Note that this method must return a new GridCellAttr for each call; do
not attempt to share the same GridCellAttr between cells. If you wish
to use the same style across a whole grid, create the attribute as a
class variable or constant, then call its
clone method to return a copy for
each call to get_attr.

### GridTableBase#set_attr

set_attr(%(arg-type)GridCellAttr% attr, Integer row, Integer col)

Set the attribute for a cell.

### GridTableBase#set_row_attr

set_row_attr(%(arg-type)GridCellAttr% attr, Integer row)

### GridTableBase#set_col_attr

set_col_attr(%(arg-type)GridCellAttr% attr, Integer col)

[This page automatically generated from the Textile source at 2023-06-09 00:45:30 +0000]