RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCustomDBGrid.DataSource Property

Identifies the link to the dataset where the data-aware grid finds its data.

Pascal
property DataSource: TDataSource;
C++
__property TDataSource DataSource;

Set DataSource to the TDataSource object that links to the dataset where the data-aware grid should fetch its data. DataSource allows the data-aware grid to read from, write to, and navigate around the dataset.  

Delphi Examples: 

 

{
The following example copies the selected rows in a db grid
to a list box.  Set the db grid Options dgRowSelect,
dgAlwaysShowSelection and dgMultiSelect to True.  Make a
multiple selecton using the CNTL key.  This example requires
a TDataSet associated with a TDataSource and a TDBGrid.}
procedure TForm1.Button2Click(Sender: TObject);
var
  i, j: Integer;
  s: string;
begin
  if DBGrid2.SelectedRows.Count>0 then
    with DBGrid2.DataSource.DataSet do
      for i:=0 to DBGrid2.SelectedRows.Count-1 do
      begin
        GotoBookmark(DBGrid2.SelectedRows.Items[i]);
        for j := 0 to FieldCount-1 do
        begin
          if (j>0) then s:=s+', ';
          s := s + FindField(Fields.Fields[j].FieldName).AsString;
        end;
        Listbox1.Items.Add(s);
        s:= '';
      end;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!