Einzelnen Beitrag anzeigen

Der schöne Günther

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#2

AW: GridPanelLayout mit leeren Zellen?

  Alt 13. Feb 2017, 08:46
Ein bisschen Code wie du das machst wäre hilfreich.

Über ControlCollection.Controls[columnIndex, rowIndex] kannst du gezielt an Positionen Controls einfügen:
Delphi-Quellcode:
function TForm10.createNewButton(const index: Integer): TButton;
begin
   Result := TButton.Create(GridPanelLayout1);
   Result.Text := 'Button ' + (index + 1).ToString();
end;

procedure TForm10.Button1Click(Sender: TObject);
const
   numRows = 10;
   emptyRows = [3, 4, 7];
var
   rows:      TGridPanelLayout.TRowCollection;
   row:    TGridPanelLayout.TRowItem;
   rowIndex:   Integer;

   newButton:   TButton;
begin
   rows := GridPanelLayout1.RowCollection;
   rows.BeginUpdate();
   try
      rows.Clear();
      for rowIndex := 0 to Pred(numRows) do begin
         row := rows.Add();
         row.SizeStyle := TGridPanelLayout.TSizeStyle.Absolute;
         row.Value := 30;

         if not (rowIndex in emptyRows) then begin
            newButton := createNewButton(rowIndex);
            GridPanelLayout1.ControlCollection.Controls[0, rowIndex] := newButton;
            newButton.Parent := GridPanelLayout1;
         end;
      end;
   finally
      rows.EndUpdate();
   end;
end;
Miniaturansicht angehängter Grafiken
unbenannt.png  
  Mit Zitat antworten Zitat