Hi,
In our application we have 2 grids with simular data.
Both grids have the same columns, and need to have the same layout.
So we need to sync the grids on column-order and column-widths.
If a columnwdith changes in the 1st grid, it must laso be changed in the 2nd (and the other way around).
Same with reordering columns with dragging.
It was pretty easy to implement this.
However when calling the method MoveColumn the columnwidths are incorrect afterwards.
I have prepared a test program for this.
You have to do the following:
* Create a new Multi-device application
* Double click the form to create an empty FormCreate Event
* Drop 1st TTMSFMXGrid on form and Align to Top
* Drop 2nd TTMSFMXGrid on form and Align to Client
* Add OnColumnDragged and OnColumnSized event to both grids
* Paste the code below instead of the implementation
* Compile and Run
* Size column in top grid with header "1-5:0", made it wider
(you now see the column in the lower grid get the same width)
* Now drag in the upper grid the column with "1-6:0" to the left on top of "1-5:0"
(it works fine for the upper grid. In the lower grid the column is moved correctly, but the columnwidth is FALSE)
If you need more information just let me know.
TIA,
John
implementation
{$R *.fmx}
var
dummyTexts: array [0 .. 9] of string = (
'zero',
'one',
'two',
'three',
'four',
'five',
'six',
'seven',
'eight',
'nine'
);
procedure TForm1.FormCreate(Sender: TObject);
begin
InitGrid(TMSFMXGrid1, '1');
InitGrid(TMSFMXGrid2, '2');
end;
procedure TForm1.InitGrid(AGrid: TTMSFMXGrid; APrefix: string);
var
c, r: Integer;
begin
AGrid.ColumnCount := 100;
AGrid.RowCount := 50;
AGrid.Options.Filtering.DropDown := True;
AGrid.Options.Filtering.MultiColumn := True;
AGrid.Options.Mouse.ColumnDragging := True;
AGrid.Options.Mouse.ColumnSizing := True;
for c := 0 to AGrid.ColumnCount - 1 do
begin
AGrid.ColumnWidths[c] := 80;
for r := 0 to AGrid.RowCount - 1 do
begin
if (r >= AGrid.FixedRows) and (c mod 3 = 2) then
AGrid.Cells[c, r] := dummyTexts[r mod 10]
else
AGrid.Cells[c, r] := Format('%s-%d:%d', [APrefix, c, r]);
end;
end;
end;
procedure TForm1.TMSFMXGrid1ColumnDragged(Sender: TObject; FromCol, ToCol: Integer);
begin
TMSFMXGrid2.MoveColumn(FromCol, ToCol);
end;
procedure TForm1.TMSFMXGrid1ColumnSized(Sender: TObject; ACol: Integer; NewWidth: Single);
begin
TMSFMXGrid2.ColumnWidths[ACol] := NewWidth;
TMSFMXGrid2.UpdateGridCells;
end;
procedure TForm1.TMSFMXGrid2ColumnDragged(Sender: TObject; FromCol, ToCol: Integer);
begin
TMSFMXGrid1.MoveColumn(FromCol, ToCol);
end;
procedure TForm1.TMSFMXGrid2ColumnSized(Sender: TObject; ACol: Integer; NewWidth: Single);
begin
TMSFMXGrid1.ColumnWidths[ACol] := NewWidth;
TMSFMXGrid1.UpdateGridCells;
end;
end.