我有以下示例代码集,如何将Data
列表元素绑定到TStringGrid
使用 LiveBindings。我需要双向更新,以便在更改网格中的列时可以更新底层的TPerson
.
我已经看到了如何使用TDataset
基于绑定执行此操作的示例,但我需要在没有TDataset
.
unit Unit15;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, System.Generics.Collections;
type
TPerson = class(TObject)
private
FLastName: String;
FFirstName: string;
published
property firstname : string read FFirstName write FFirstName;
property Lastname : String read FLastName write FLastName;
end;
TForm15 = class(TForm)
StringGrid1: TStringGrid;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
Data : TList<TPerson>;
end;
var
Form15: TForm15;
implementation
{$R *.dfm}
procedure TForm15.FormCreate(Sender: TObject);
var
P : TPerson;
begin
Data := TList<TPerson>.Create;
P := TPerson.Create;
P.firstname := 'John';
P.Lastname := 'Doe';
Data.Add(P);
P := TPerson.Create;
P.firstname := 'Jane';
P.Lastname := 'Doe';
Data.Add(P);
// What can I add here or in the designer to link this to the TStringGrid.
end;
end.