1. Home
  2. /
  3. Docs
  4. /
  5. Articles Report Writer
  6. /
  7. Dialog Components
  8. /
  9. DBCheckList Dialog Contro...

DBCheckList Dialog Control

The DB Check List control displays a dataset as a multi-column grid where every row has a checkbox. Users can check any number of rows, and the control returns the selected key values as a comma-delimited string formatted for direct use in a SQL IN clause. It is ideal for letting users pick multiple customers, items, categories, or any other entity before the report runs.

The selected keys are stored in a report variable and survive the FastReport component rebuild between the dialog and report phases, so they are always available in BeforeStartReport and throughout the report.


DataSoft's Articles DB Checklist Dialog Control

Adding to a Report

Drop a DB Check List onto a dialog page and set the following in the Object Inspector:

  1. Set DataSetName to the dataset that provides the list rows
  2. Set KeyFieldName to the field whose value is returned for each checked row
  3. Set KeyType to match the data type of the key field
  4. Optionally double-click the control to open the Column Editor and choose which columns to display

If ColumnDefs is left empty, all fields from the dataset are shown as columns automatically.


Column Editor

Double-clicking the control in the report designer opens the Column Editor, which works the same way as the DB Lookup Extended column editor. Each column has three settings:

SettingDescription
Field NameThe dataset field to display. If the dataset is open, a dropdown lists available fields.
CaptionThe column header text shown in the grid
WidthThe column width in pixels

Column definitions are stored as the ColumnDefs property in the format FieldName|Caption|Width separated by semicolons. Leave ColumnDefs empty to show all dataset fields automatically.


SelectedKeys Format

The SelectedKeys property returns a comma-delimited string of the checked key values, formatted based on the KeyType property so it can be used directly in a SQL IN clause.

KeyTypeExample OutputUse for
ktNumber1,2,3Integer or numeric key fields
ktString'Acme','Bolt Co','Smith Ltd'Text key fields
ktDate'2024-01-01','2024-06-30'Date key fields (stored as ISO yyyy-mm-dd)
ktBoolean1,0,1Boolean key fields โ€” uses BoolTrueValue / BoolFalseValue

The output is ready to drop straight into a SQL WHERE clause:

WHERE CustomerID IN ([DBCheckList1.SelectedKeys])

Properties

PropertyTypeDefaultDescription
DataSetNameStringName of the report dataset that provides the list rows
KeyFieldNameStringThe field whose value is collected for each checked row
KeyTypeTfrxDBCheckListKeyTypektNumberControls how key values are formatted in SelectedKeys. Options: ktNumber, ktString, ktDate, ktBoolean.
BoolTrueValueString‘1’The value written to SelectedKeys for a checked boolean key
BoolFalseValueString‘0’The value written to SelectedKeys for an unchecked boolean key
ColumnDefsStringColumn definitions for the grid. Leave empty to show all dataset fields. Set via the Column Editor or as a formatted string.
SelectedKeysStringThe comma-delimited list of checked key values, SQL-formatted based on KeyType. Read or write from script.
AutoOpenDataSetBooleanFalseAutomatically opens the dataset if it is not already open when the control initialises
SearchVisibleBooleanTrueShows or hides the search box above the grid
ButtonsVisibleBooleanTrueShows or hides the Select All and Deselect All buttons

Script Methods

MethodDescription
SelectAllChecks all rows in the grid
DeselectAllUnchecks all rows in the grid
RefreshRepopulates the grid from the dataset. Use this if the dataset contents change after the control has already initialised.

Report Variable

The control automatically writes SelectedKeys to a report variable each time a checkbox changes. The variable is named after the control:

<ControlName>.SelectedKeys

For example, if the control is named DBCheckList1, the variable is DBCheckList1.SelectedKeys. Use it in report expressions or macro substitutions:

// In a SQL macro โ€” replace directly into the query text
WHERE CustomerID IN ([DBCheckList1.SelectedKeys])

// In a report text object expression
Selected: [DBCheckList1.SelectedKeys]

Events

EventDescription
OnClickFires when the control is clicked
OnEnterFires when focus enters the control
OnExitFires when focus leaves the control
OnKeyDownFires when a key is pressed down
OnKeyPressFires when a key is pressed
OnKeyUpFires when a key is released
OnMouseDownFires when a mouse button is pressed
OnMouseMoveFires when the mouse moves over the control
OnMouseUpFires when a mouse button is released

Examples

Basic setup โ€” numeric key

Set DataSetName to your customer query, KeyFieldName to CustNo, and KeyType to ktNumber. The user checks the customers they want and SelectedKeys returns something like 1,4,7.

Using SelectedKeys in BeforeStartReport

procedure BeforeStartReport;
begin
  // Guard against nothing being selected
  if DBCheckList1.SelectedKeys = '' then
    RaiseException('Please select at least one customer.');

  // Pass the selected keys as a macro for SQL substitution
  SetParam('qryReport', 'CustomerList', DBCheckList1.SelectedKeys);
end;

Using SelectedKeys directly in a SQL macro

If your dataset uses macro substitution, you can drop SelectedKeys directly into the SQL at design time:

SELECT * FROM Orders
WHERE CustomerID IN (&CustomerList)

Then in BeforeStartReport:

qryOrders.Macros.MacroByName('CustomerList').Value :=
  DBCheckList1.SelectedKeys;

String key type

Set KeyType to ktString when the key field contains text values. SelectedKeys will wrap each value in single quotes:

// KeyType = ktString
// SelectedKeys returns: 'FL','GA','TX'

// Use in SQL:
WHERE StateCode IN ([DBCheckList1.SelectedKeys])

Pre-selecting values from script

// Pre-check specific keys when the dialog opens
// For ktNumber: comma-delimited numbers
DBCheckList1.SelectedKeys := '1,4,7';

// For ktString: include the quotes
DBCheckList1.SelectedKeys := '''Acme'',''Bolt Co''';

Select all and deselect all from script

// Check everything
DBCheckList1.SelectAll;

// Uncheck everything
DBCheckList1.DeselectAll;

Combining with a date range

procedure BeforeStartReport;
begin
  if DBCheckList1.SelectedKeys = '' then
    RaiseException('Please select at least one item.');

  SetParam('qryReport', 'ItemList',  DBCheckList1.SelectedKeys);
  SetParam('qryReport', 'StartDate', DateRangePicker1.StartDate);
  SetParam('qryReport', 'EndDate',   DateRangePicker1.EndDate);
end;

Hiding the search and buttons for a compact layout

DBCheckList1.SearchVisible  := False;
DBCheckList1.ButtonsVisible := False;

Refreshing after a dataset change

// If another control changes the dataset contents (e.g. a filter),
// call Refresh to reload the grid
DBCheckList1.Refresh;