Rx DB Grids

RX Library

Control Name Unit Class
RX DB Grids DbGrid TRxDBGrid

Description: TRxDBGrid component provides you with the ability to:

  • change the background color and font displayed within individual cells and entire rows and columns (with OnGetCellParams, OnGetBtnParams event);
  • save and restore columns order and display width in ini-files or system registry (using the SaveLayout, RestoreLayout, SaveLayoutReg, RestoreLayoutReg methods or IniStorage property);
  • display icons for BLOB, memo, OLE and picture fields (if ShowGlyphs property is True);
  • select multiple records (if MultiSelect = True);
  • convert columns headings to buttons (TitleButtons property, OnTitleBtnClick event);
  • define fixed, non-scrollable columns in the left-hand side of the grid (using FixedCols property).

Using class TRxDBGrid

There is example of using TRxDBGrid to display customers data (CUSTOMER.DB table from DBDEMOS alias) with using OnGetCellParams event:

procedure TForm1.rxDBGrid1GetCellParams(Sender: TObject; Field: TField; AFont: TFont; var Background: TColor; Highlight: Boolean);

var
__OldDate, NewDate: TDateTime;
__DataSet: TDataSet;
begin
__if Field.FieldName = 'Company' then
____AFont.Style := AFont.Style + [fsBold]
__else
____if Field.FieldName = 'Contact' then
______if not Highlight then Background := clYellow;
__if not Highlight then begin
____OldDate := EncodeDate(1990, 1, 1);
____NewDate := EncodeDate(1995, 1, 1);
____DataSet := (Sender as TrxDBGrid).DataSource.DataSet;
__if DataSet.FieldByName('LastInvoiceDate').AsDateTime < OldDate then
____Background := clLime { oldest } else
__if DataSet.FieldByName('LastInvoiceDate').AsDateTime >= NewDate then
____AFont.Color := clRed; { newest }
__end;
end;

Use the TRxDBGrid component to display data from a dataset component in a spreadsheet-like grid instead standard TDBGrid component.


Property ClearSelection
Declaration: ClearSelection: Boolean;


Property FixedCols
Declaration: FixedCols: Integer;

The FixedCols property can be used to specify a number of fixed columns in the grid. The number of fixed columns must always be less than the total number of columns or fields in the grid. Fixed columns are always read-only when adding or editing records. This allows program or database generated fields such as record keys to be locked from user update. Values can be added to these fields by the DBMS when posting a record; in the AfterInsert event, in the OnNewRecord or in the BeforePost event of the linked dataset. The value can be set from 0 to one less than the total number of columns (or fields in the dataset).

Associated with the FixedCols property is a FixedColor property which allows you to change the color of the fixed columns.


Property InplaceEditor
Declaration: InplaceEditor: TInplaceEditor;

Runtime only. InplaceEditor is the default editor used by the grid to edit a cell’s value. You may wish to reference this property if you need to access the currently edited value or dynamically manipulate the editor. For instance, if you wish to change the color of the editor when it has an invalid value.


Property MultiSelect
Declaration: MultiSelect: Boolean;

When True, the user can select multiple, non-contiguous rows using Ctrl+click or Shift+arrow keys. The behavior is similar to a multi-select list box. The records you select are represented as bookmarks and are stored in the SelectedRows property. The SelectedRows property is an object of type TBookmarkList.


Property SelectedRows
Declaration: SelectedRows: TBookmarkList;

SelectedRows is a set of bookmarks to all the records in the dataset that correspond to rows selected in the grid. Use the properties and methods of the TBookmarkList object returned by

SelectedRows to

  • Determine the number of rows in the grid that are selected.
  • Determine whether the current record in the dataset is selected.
  • Determine whether a particular record in the dataset is selected.
  • Delete all selected rows from the dataset.

SelectedRows is only meaningful when the MultiSelect property is True (or Options property includes dgMultiSelect in 32-bit version). You can navigate through selected rows in the dataset by using GotoSelection method of TRxDBGrid.


Property ShowGlyphs
Declaration: ShowGlyphs: Boolean;

This option would allow bitmaps or glyphys to be displayed.


Property TitleButtons
Declaration: TitleButtons: Boolean;

When this property is True, the column headings of each column will act as a button. When the user clicks on one, it will depress and fire the OnTitleBtnClick event. You can also handle OnCheckButton and OnGetBtnParams events to change title buttons property.


Event OnCheckButton
Declaration: OnCheckButton: TCheckTitleBtnEvent;

When the checkbutton is checked or unchecked, this event is triggered.


Event OnGetBtnParams
Declaration: OnGetBtnParams: TGetBtnParamsEvent;

This event which executes just prior to painting each title cell (when TitleButtons is True), allows you to change both the font and background colors of each title button.


Event OnGetCellParams
Declaration: OnGetCellParams: TGetCellParamsEvent;

This event, which executes just prior to painting the field values within each grid cell, allows you to change both the font and background colors of individual cells.


Event OnGetCellProps
Declaration: OnGetCellProps: TGetCellPropsEvent;

Obsolete event (for backward compatibility only). Use OnGetCellParams instead.


Event OnTitleBtnClick
Declaration: OnTitleBtnClick: TTitleClickEvent;

The OnTItleBtnClick event occurs when the user clicks on one of the column headings in the TRxDBGrid. The TitleButtons property must be True in order for this event to occur.


Method GotoSelection
Declaration: procedure GotoSelection(Index: Integer);

This method moves the index to that particular row or selection.


Method RestoreLayout
Declaration: procedure RestoreLayout(IniFile: TIniFile);

From the inifile, this method extracts the layout property information and restores the property information to the column, rows of the string-grid.

See also:
FormStorage.


Method RestoreLayoutReg
Declaration: procedure RestoreLayoutReg(IniFile: TRegIniFile);

From the inifile, this method extracts the layout property information and restores the property information to the column, rows of the string-grid.

See also:
FormStorage.


Method SaveLayout
Declaration: procedure SaveLayout(IniFile: TIniFile);

This method saves the current layout information of the DbGrid to the INI file.


Method SaveLayoutReg
Declaration: procedure SaveLayoutReg(IniFile: TRegIniFile);

This method saves the current layout information of the DbGrid to the INI file.


Method SelectAll
Declaration: procedure SelectAll;

This method adds all records to the list of currently selected records (if MultiSelect=True).


Method ToggleRowSelection
Declaration: procedure ToggleRowSelection;

This method adds or removes the record relating to the current grid row to the list of currently selected records if MultiSelect property is True. For instance, you can call this method from OnKeyPress event handler.


Method UnselectAll
Declaration: procedure UnselectAll;

This method removes all records from the list of currently selected records (if MultiSelect=True).


Type TBookmarkList
Declaration: TBookmarkList = class;

When you set MultiSelect property of a TRxDBGrid to True, you give yourself the ability to select multiple records within the grid. The records you select are represented as bookmarks and are stored in the SelectedRows property. The SelectedRows property is an object of type TBookmarkList. The properties and methods are described below.

The Items property is a List of TBookmark. The Count property returns the number of currently selected items in the DBGrid The Clear method will free all the selected records within the DBGrid

  • The Delete method will delete all the selected rows from the dataset
  • The Find method determines whether a bookmark is in the selected list.
  • Use the Find method to locate the position of the bookmarked record within the selected list in the DBGrid.
  • The IndexOf method returns the index of the bookmark within the Items property.
  • The Refresh method returns a boolean value to notify whether any orphans were dropped (deleted) during the time the record has been selected in the grid.
  • The Refresh method can be used to update the selected list to minimize the possibility of accessing a deleted record.
  • The CurrentRowSelected property returns a boolean value and determines whether the current row is selected or not.

NOTE: In 32-bit version Delphi this class is declared in DBGRIDS.PAS unit.


Type TCheckTitleBtnEvent
Declaration: TCheckTitleBtnEvent = procedure (Sender: TObject; ACol: Longint; Field: TField; var Enabled: Boolean) of object;

TCheckTitleBtnEvent is the type of the OnCheckButton event of the TRxDBGrid component.


Type TDBLabelOptions
Declaration: TDBLabelOptions = (doCaption, doGlyph, doBoth);

TDBLabelOptions is a set of available values for the ShowOptions property of the TDBStatusLabel control.


Type TDBLabelStyle
Declaration: TDBLabelStyle = (lsState, lsRecordNo);

TDBLabelStyle is a set of available values for the Style property of the TDBStatusLabel control.


Type TGetBtnParamsEvent
Declaration: TGetBtnParamsEvent = procedure (Sender: TObject; Field: TField; AFont: TFont; var Background: TColor; IsDown: Boolean) of object;

TGetBtnParamsEvent is the type of the OnGetBtnParams event of the TRxDBGrid component.


Type TGetCellParamsEvent
Declaration: TGetCellParamsEvent = procedure (Sender: TObject; Field: TField; AFont: TFont; var Background: TColor; Highlight: Boolean) of object;

TGetCellParamsEvent is the type of the OnGetCellParams event of the TRxDBGrid component.


Type TGetCellPropsEvent
Declaration: TGetCellPropsEvent = procedure (Sender: TObject; Field: TField; AFont: TFont; var Background: TColor) of object;

TGetCellPropsEvent is the type of the OnGetCellProps (obsolete) event of the TRxDBGrid component.


Type TGetStringEvent
Declaration: TGetStringEvent = function(Sender: TObject): string of object;

The TGetStringEvent points to a method that handles the retrieving of the string displayed as a dataset name in a TDBStatusLabel.


Type TGlyphAlign
Declaration: TGlyphAlign = glGlyphLeft..glGlyphRight;

TGlyphAlign is a set of available values for the GlyphAlign property of the TDBStatusLabel control.


Type TTitleClickEvent
Declaration: TTitleClickEvent = procedure (Sender: TObject; ACol: Longint; Field: TField) of object;

TTitleClickEvent is the type of the OnTitleClick event of the TRxDBGrid component.


Index Page | About | Download
Creation Date: 4 Feb 1998 | Last Update: 16 Mar 2000