www.mwasoftware.co.uk

TDBControlGrid

 

TDBControlGrid is a lookalike rather than a clone for the Delphi TDBCrtlGrid. TDBControlGrid is a single column grid that replicates a TWinControl - typically a TPanel or a TFrame in each row. Each row corresponds to a row of the linked DataSource. Any data aware control on the replicated (e.g.) TPanel will then appear to have the appropriate value for the row.

Unlike the Delphi TDBCtrlGrid, there are no restrictions on which controls can be used on the replicated panel. In principle, any visual control may be used. The “csReplicable” property is not used by TDBControlGrid. However, there can be performance issues with a large number of controls on the panel or when there is a high latency to draw one or more controls.

To use the new control, simply drop it on to a form at design time and size it appropriately. Then separately drop a TPanel on to the same form and populate it with appropriate child controls, typically data aware controls using the same DataSource.

Now link to TDBControlGrid DrawPanel property to this panel. The panel should then be repositioned as a child control of the TDBControlGrid and occupying the top and only row of the grid. The row height should be set to the panel height and the panel width will the set to the with of the grid row. The panel can be unlinked at any time.

Now set the TDBControlGrid.DataSource to the common data source for the controls on the panel.

When you build and run your project and open the DataSource's dataset, the TDBControlGrid should show a row for each row in the dataset and the child controls on each row should have the appropriate values for the row.

When the grid has the focus, you can move between rows using the up and down arrow keys, page Up and Page Down, Ctrl+Home and Ctrl+End jump to beginning and end respectively. You can also use the mouse to change between rows, either by clicking on a row or the scroll bar.

Pressing the down arrow key on the last row should append a new row – as long as the “Disable Insert” TDBControlGrid.Option is not selected.

All rows may be edited in situ. Moving between rows should automatically post the changes. The “escape” key may be used to cancel row edits before they are posted.

A row may be deleted by calling the underlying DataSet's Delete method.

See the TDBControlGrid example code for guidance on how to use the control. This example requires IBX and uses the Firebird example employee database.

Note: With GTK the row image is created by a screen grab (in GTK itself). This can give rise to unexpected results if the control is obscured when caching takes place.

TDBControlGrid Properties

DrawPanel

TWinControl

This control will be replicated for each row in the DataSet. Typically a TPanel or a Tframe.

Options

TPanelGridOptions

Similar to a TDBGrid, but limited to:

  • Cancel On Exit

  • Disable Insert

  • Show Indicator Column

DataSource

TDataSource

A row is replicated for every row in this dataset.

DefaultPositionAtEnd

Boolean

When the dataset is opened then it is initially positioned at the last record if this property is true,

 

TDBControlGrid new Events

OnKeyDownHander

The TDBControlGrid uses a KeyDown handler to intercept edit keys while the Draw Panel is active. For example, to process an “escape” key as a cancel edit. You can write your own keydown handler to modify this behaviour.