TIBDynamicGrid

 
The TIBDynamicGrid is illustrated above using Firebird's example “employee” databases.
 

In use, it looks just like a TDBGrid and is a TDBGrid descendent. Any project that uses IBX and TDBGrid can thus be quickly converted to using TIBDynamicGrid. The control uses SQL Manipulation to manage column sorting.

The above example can be found in “ibx/examples/employee” and illustrates most of the benefits of TIBDynamicGrid.

 
Column Properties
 
Column Properties

Most of TIBDynamicGrid's new features are accessed via the column editor and are properties of each column in the grid. The new column properties are given below.

AutoSizeColumn

Boolean

If true then the column is automatically resized to fill the grid. More than one column can have this property set to true.

ColumnTotalsControl

TControl

Optional. Used to identity a control (typically a TDBEdit or TDBText) to be kept in vertical alignment with the column, and to have the same width. Note that the horizontal positioning is unaffected by grid resize, and hence the total can be placed either above or below the grid.

InitialSortColumn

Boolean

Identifies the column used to sort the grid when the dataset is first opened.

DBLookupProperties

TDBLookupProperties

These properties are copied to a TIBLookupComboBox when it is used as a column editor. Setting TDBLookupProperties.ListSource implictly requests this as the column editor instead of a normal pick list.

If the  TDBLookupProperties.DataFieldName is not set then the control works as a “pick list” with its values taken from the List Source DataSet.

If the  TDBLookupProperties.DataFieldName is set then it works as full lookup list. The DataFieldName identifies a field in the parent TIBDynamicGrid.DataSource.DataSet. This field does not have to be visible in the grid. When the editor completes, the identified field is set to the value of the List Source field identified by  TDBLookupProperties.KeyField.

 

TIBDynamicGrid New Properties

EditorPanel

TControl

When set, this control (typically a TPanel or TFrame) is used as the Editor Panel (see below).

ExpandEditorPanelBelowRow

Boolean

When set and an editor panel is displayed, the row height is set to the current row height plus the panel height and the Editor Panel placed under the row. That is, the original row is still displayed with the editor panel beneath it. The default is that the editor panel appears to replace the row.

AllowColumnSort

Boolean

Enables column sorting by column header click (default true).

Descending

Boolean

Determines the initial sort order. Default is false i.e. ascending sort order.

DefaultPositionAtEnd

Boolean

Determines the initially selected row when the dataset is first opened. If true then the last row is selected, otherwise the first row. Default: false.

IndexFieldNames

String

This is a semi-colon separated list of one or more dataset fieldnames. Typically this is the primary key for the dataset. Used for automatic reselection of rows after the dataset is reopened.

A property editor is available for design time field name selection.

 

TIBDynamicGrid new Events

OnBeforeEditorHide

This event is called before the Editor Panel is hidden. Can be used to validate changes.

OnEditorPanelShow

This event is called after the Editor Panel is made visible

OnEditorPanelHide

This event is called after the Editor Panel is hidden. Can be used to do any additional tidying up needed.

OnKeyDownHander

The TIBDynamicGrid uses a KeyDown handler to intercept edit keys while the Editor 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.

OnColumnHeaderClick

Called when a column header is clicked and before the dataset is re-sorted. Can be used to modify the column index for the sort.

OnUpdateSortOrder

Called when the dataset select SQL is being modified prior to resorting the dataset. Can be used to modified the SQL “Order by” clause. e.g. to add a subsort column. For example, useful when one column has a “year” and the next column is the “month”. Clicking on “year” can then made to subsort on “month”.

OnRestorePosition

Called when the dataset is opened and may be used to override the initially selected record. The event provides a read/write argument (Location) that is an array of variants. This is either an empty zero length array or contains the same number of elements as there are indexnames (See IndexFieldNames property). In the latter case, it contains the index key values for the previously selected row (i.e. when the dataset was last closed). The first time the dataset is opened the array is empty.

The location can be inspected and replaced by an alternative location (index key values) or set to empty. In the former case, the grid will attempt to locate the selected row. In the latter case, the default position is selected (see DefaultPositionAtEnd property).

 

The Editor Panel

An Editor Panel may be any TControl available on the form. However, in practice, it is typically either a TPanel or a Tframe. The example shows a TPanel being used as an Editor Panel.

You can create an Editor Panel by simply dropping it on to the same form as the TIBDynamicGrid and then selecting it as the value of the  TIBDynamicGrid.EditorPanel property.

To be useful, the Editor Panel should be populated with data aware controls that use the same DataSource as the grid and are individually used to edit fields in the same row. The height of the panel should be the minimum necessary as this will determine the row height when it is visible.

At run time, the Editor Panel is automatically hidden until called into use by either:

  1. a)Pressing “F2” when the Dynamic Grid has the focus. 

  2. b)Clicking on the left hand indicator column, or 

  3. c)Calling the  TIBDynamicGrid.ShowEditorPanel method. 

In order to show the editor panel, the following actions are performed by the  TIBDynamicGrid:

The current row can now be edited using the child controls on the Editor Panel – that is as long as their DataSource is the same as the grid's.

The Editor Panel is hidden (and any changes Posted to the DataSet) when:

  1. a)A different row is selected by the mouse or up/down arrow keys 

  2. b)The Escape Key is Pressed (cancels the changes) 

  3. c)“F2” is pressed. 

  4. d)The  TIBDynamicGrid.HideEditorPanel method is called. 

Once the Editor Panel is hiddent, the current row is re-sized back to its correct height.