Skip to main content
Table of Contents

TTMSFNCDataGridDatabaseAdapter.DataSource Property

The data source whose dataset is shown in the grid.

API unit family: TMSFNCDataGridDatabaseAdapter Declaring type: TTMSFNCDataGridDatabaseAdapter Inherited from: TTMSFNCCustomDataGridDatabaseAdapter Type: TDataSource

Syntax

FMX.TMSFNCDataGridDatabaseAdapter.hppPascalC++
property DataSource: TDataSource;
__property Data::Db::TDataSource* DataSource = {read=GetDataSource, write=SetDataSource};

Remarks

The grid is filled when the dataset is open and the adapter is active; opening, closing, scrolling, and editing the dataset are followed automatically through DataLink. Unidirectional datasets are rejected with an EDatabaseError when they become active.

Assigning nil clears the grid data and, when AutoRemoveColumns is True, removes all grid columns. The adapter is notified when the data source is freed and disconnects itself.

Usage examples

Bind a TTMSFNCDataGrid to a FireDAC TFDTable

Drop a TTMSFNCDataGridDatabaseAdapter, point it at a TDataSource, and the grid is automatically populated when the dataset opens.

Bind a TTMSFNCDataGrid to a FireDAC TFDTablePascalC++
procedure TForm1.FormCreate(Sender: TObject);
begin
  // Wire up the adapter
  Adapter.DataGrid    := Grid;
  Adapter.DataSource  := DataSource1;        // TDataSource attached to FDTable1

  // Auto-create one column per dataset field; remove columns when fields go away.
  Adapter.AutoCreateColumns := True;
  Adapter.AutoRemoveColumns := True;

  // Open the dataset — the grid populates itself.
  FDTable1.Active := True;

  // Optional: shrink the row-number column after the data loads.
  Grid.ColumnWidths[0] := 30;
  Grid.AutoSizeColumns;
end;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  // Wire up the adapter
  Grid->Adapter       = Adapter;  // the adapter is attached from the grid side
  Adapter->DataSource = DataSource1;        // TDataSource attached to FDTable1

  // Auto-create one column per dataset field; remove columns when fields go away.
  Adapter->AutoCreateColumns = true;
  Adapter->AutoRemoveColumns = true;

  // Open the dataset - the grid populates itself.
  FDTable1->Active = true;

  // Optional: shrink the row-number column after the data loads.
  Grid->ColumnWidths[0] = 30;
  Grid->AutoSizeColumns();
}

Read the related guide

Configure the dataset-level master/detail link before opening the datasets and assigning them through the DataGrid database adapters.

Link the detail dataset to the selected master recordPascalC++
procedure TForm1.ConfigureMasterDetailDatasets;
begin
  MasterTable.TableName := 'Orders';
  DetailTable.TableName := 'OrderDetails';

  MasterDataSource.DataSet := MasterTable;
  DetailDataSource.DataSet := DetailTable;

  DetailTable.MasterSource := MasterDataSource;
  DetailTable.MasterFields := 'OrderID';
  DetailTable.IndexFieldNames := 'OrderID';
end;
void __fastcall TForm1::ConfigureMasterDetailDatasets()
{
  MasterTable->TableName = "Orders";
  DetailTable->TableName = "OrderDetails";

  MasterDataSource->DataSet = MasterTable;
  DetailDataSource->DataSet = DetailTable;

  DetailTable->MasterSource = MasterDataSource;
  DetailTable->MasterFields = "OrderID";
  DetailTable->IndexFieldNames = "OrderID";
}

Read the related guide

One grid shows orders, a second grid shows the items of the selected order. Linking is done at the dataset level via FireDAC's MasterSource.

Master-detail with two grids and a FireDAC linkPascalC++
procedure TForm1.FormCreate(Sender: TObject);
begin
  // Master grid bound to FDTable1 (orders)
  MasterAdapter.DataGrid    := MasterGrid;
  MasterAdapter.DataSource  := DataSource1;
  MasterAdapter.AutoCreateColumns := True;

  // Detail grid bound to FDTable2 (order items). The dataset itself does the
  // linking via MasterSource + MasterFields, configured at design time.
  DetailAdapter.DataGrid    := DetailGrid;
  DetailAdapter.DataSource  := DataSource2;
  DetailAdapter.AutoCreateColumns := True;

  // Open both — the detail dataset filters automatically as the master row
  // changes because of the master/detail FireDAC linkage.
  FDTable1.Active := True;
  FDTable2.Active := True;
end;
void __fastcall TForm1::FormCreate(TObject *Sender)
{
  // Master grid bound to FDTable1 (orders)
  MasterGrid->Adapter     = MasterAdapter;
  MasterAdapter->DataSource = DataSource1;
  MasterAdapter->AutoCreateColumns = true;

  // Detail grid bound to FDTable2 (order items). The dataset itself does the
  // linking via MasterSource + MasterFields, configured at design time.
  DetailGrid->Adapter     = DetailAdapter;
  DetailAdapter->DataSource = DataSource2;
  DetailAdapter->AutoCreateColumns = true;

  // Open both - the detail dataset filters automatically as the master row
  // changes because of the master/detail FireDAC linkage.
  FDTable1->Active = true;
  FDTable2->Active = true;
}

Read the related guide