Unlike the TDBGrid object, which displays each record in a single row, TDBCtrlGrid displays the records in a free-form layout. Each record is displayed on its own panel. You design only one panel at design time and at run-time, the DBCtrlGrid replicates that panel for each record displayed.
At runtime, you can use a database navigator (TDBNavigator) to move through the records, and to insert, delete, and edit the data.
The DBCtrlGrid has a few properties worth mentioning. You use the Orientation property to determine where the scrollbar is to be placed. You use PanelWidth and PanelHeight to set the width and height of a cell in the grid. The RowCount property determines how many records to show at one time.
The DBCtrlGrid component has one event, OnPaintPanel. This event is fired each time a grid cell needs painting. You can respond to this event in order to draw on the background of the panel.
Example with a SQLite database "geo.sqlite", an FDConnection, an FDQuery, a DataSource, a DBNavigator and a DBCtrlGrid:
2. Start Delphi and start a new project: menu File > New > VCL Forms Application.
3. In the Object Inspector:
- set property Connected of FDConnection1 to False;
4. Drop 5 DBEdit controls on the first panel of the DBCtrlGrid.
Set their property DataSource to DataSource1.
5. Drop a DBMemo on the first panel of the DBCtrlGrid.
6. Set a few properties of the DBCtrlGrid:
- set rowcount to 3;
Our source code is remarkably short:
At runtime, this gives:
Some data controls cannot be used with TDBCtrlGrid, e.g. TDBRadioGroup.