I want to link a TGrid to a TDataSource at runtime.
I want to link a TGrid to a TDataSource at runtime.
Can anyone point me to an up to date example of how to achieve this please?
Can anyone point me to an up to date example of how to achieve this please?
I have managed to get it linked, but the grid only displays the headers. Here's my code, any help appreciated.
ReplyDeleteprocedure TForm1.Button1Click(Sender: TObject);
var
BindSourceDB1: TBindSourceDB;
BindingsList1: TBindingsList;
ALinkGridToDataSourceBindSourceDB: TLinkGridToDataSource;
grid1: TGrid;
begin
grid1 := TGrid.Create(Self);
grid1.Parent := Form1;
grid1.Align := TAlignLayout.Client;
BindSourceDB1 := TBindSourceDB.Create(Self);
BindSourceDB1.DataSet := UniQuery1;
BindingsList1 := TBindingsList.Create(Self);
BindingsList1.UseAppManager := True;
ALinkGridToDataSourceBindSourceDB := TLinkGridToDataSource.Create(BindingsList1);
ALinkGridToDataSourceBindSourceDB.DataSource := BindSourceDB1;
ALinkGridToDataSourceBindSourceDB.GridControl := grid1;
ALinkGridToDataSourceBindSourceDB.Category := 'Quick Bindings';
end;
TLinkObservers.ControlChanged(LiveGrid); will update the data in a changed LiveBinding control. I also use this to change the datasource that a LiveGrid is linked to:
ReplyDeleteLinkGridToDataSourceBindSourceDBData.DataSource := BindSourceDB;
LinkGridToDataSourceBindSourceDBData.Active := True;
Thanks Eli that worked!
ReplyDeleteI added the LinkGridToDataSourceBindSourceDBData.Active := True and also the TLinkObservers.ControlChanged(grid1);