unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs,
FMX.StdCtrls, FMX.Grid, FMX.Layouts, FMX.Header;
type
THeaderCell =
class (FMX.Header.THeader)
private
procedure InternalResize (Sender : TObject);
protected
procedure SetData (
const Value: TValue);
override;
public
constructor Create (Owner : TComponent);
override;
end;
THeaderColumn =
class (FMX.Grid.TColumn)
protected
function CreateCellControl : TStyledControl;
override;
end;
// Für den Zugriff auf die Scrollbars
TGrid =
class (FMX.Grid.TGrid)
end;
TForm1 =
class(TForm)
Grid1: TGrid;
Column1: TColumn;
ImageColumn1: TImageColumn;
StringColumn1: TStringColumn;
Grid2: TGrid;
StyleBook1: TStyleBook;
procedure FormCreate(Sender: TObject);
procedure Grid1Paint(Sender: TObject; Canvas: TCanvas;
const ARect: TRectF);
procedure Grid1SelChanged(Sender: TObject);
procedure Grid2SelChanged(Sender: TObject);
private
{ Private-Deklarationen }
procedure SyncVScrollBarValue (Sender : TObject);
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure THeaderCell.InternalResize (Sender : TObject);
begin
Items [0].Width := Width + 1
end;
procedure THeaderCell.SetData (
const Value : TValue);
begin
Items [0].Text := Value.AsString
end;
constructor THeaderCell.Create (Owner : TComponent);
var
i : THeaderItem;
begin
inherited Create (Owner);
i := THeaderItem.Create (Self);
i.Enabled := False;
AddObject (i);
OnResize := InternalResize
end;
function THeaderColumn.CreateCellControl : TStyledControl;
begin
Result := THeaderCell.Create (Self)
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Grid1.OnVScrollChange := SyncVScrollBarValue;
Grid2.AddObject (THeaderColumn.Create (Self));
Grid2.Position.X := Grid1.Position.X;
Grid2.Position.Y := Grid1.Position.Y;
Column1.Enabled := False;
Column1.Width := Grid2.Width - 5
end;
procedure TForm1.Grid1Paint(Sender: TObject; Canvas: TCanvas;
const ARect: TRectF);
begin
if Grid1.HScrollBar.Visible
then
Grid2.Height := Grid1.Height - Grid1.HScrollBar.Height - 2
else
Grid2.Height := Grid1.Height
end;
procedure TForm1.Grid1SelChanged(Sender: TObject);
begin
Grid2.Selected := Grid1.Selected
end;
procedure TForm1.Grid2SelChanged(Sender: TObject);
begin
Grid1.Selected := Grid2.Selected
end;
procedure TForm1.SyncVScrollBarValue(Sender: TObject);
begin
Grid2.VScrollBar.Value := Grid1.VScrollBar.Value
end;
end.