The GridPanel has issues! Am I doing something wrong? First row at column 2 is a bug on resizing the form. Tested with Delphi XE 6 and 10.2.2! Place a TGridPanel to the Form and set "Align" to "alClient". Start and resize form.
Try the following code:
procedure TForm5.Button1Click(Sender: TObject);
var
Col,Row: Integer;
CI: TControlItem;
Panel: TPanel;
Rows, Cols: Integer;
begin
GridPanel1.RowCollection.BeginUpdate;
GridPanel1.ColumnCollection.BeginUpdate;
GridPanel1.ColumnCollection.BeginUpdate;
GridPanel1.RowCollection.Clear;
GridPanel1.ColumnCollection.Clear;
Rows := 6;
Cols := 4;
for Row := 1 to Rows do
begin
with GridPanel1.RowCollection.Add do
begin
SizeStyle := ssPercent;
Value := 100 / Rows;
end;
end;
for Col := 1 to Cols do
begin
with GridPanel1.ColumnCollection.Add do
begin
SizeStyle := ssPercent;
Value := 100 / Cols;
end;
end;
for Row := 0 to GridPanel1.RowCollection.Count - 1 do
begin
for Col := 0 to GridPanel1.ColumnCollection.Count - 1 do
begin
Panel := TPanel.Create(Self);
Panel.Parent := GridPanel1;
CI := GridPanel1.ControlCollection.Add;
CI.Column := Col;
CI.Row := Row;
Panel.Caption := 'Row ' + Row.ToString + ' Col ' + Col.ToString;
CI.Control := Panel;
end;
end;
GridPanel1.ColumnCollection.EndUpdate;
GridPanel1.RowCollection.EndUpdate;
GridPanel1.ColumnCollection.EndUpdate;
end;