Einzelnen Beitrag anzeigen

Der schöne Günther

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

Kann ich in einem GridPanel Zeilen mittendrin einfügen?

  Alt 28. Aug 2017, 17:50
Angenommen ich habe ein TGridPanel im Layout 1x5, also fünf Zeilen. Ich kann sagen myGridpanel.RowCollection.Add() oder myGridpanel.RowCollection.Insert(2) um eine neue Zeile einzufügen, beide tun das gleiche. Bei einem Insert(..) hätte ich, wie die Hilfe dazu sagt, erwartet dass ich es an einer bestimmten Stelle einfügen kann.

Beide Code-Schnipsel tun das gleiche, nämlich eine neue Zeile am Ende einfügen. Was fehlt mir?

Delphi-Quellcode:
procedure TForm17.Button1Click(Sender: TObject);
const
   wantedIndex = 2;
var
   rows:      TRowCollection;
   newRow:      TRowItem;
   rowIndex:   Integer;
   rowHeight:   Single;
begin
   rows := GridPanel1.RowCollection;

   rows.BeginUpdate();
   try
      newRow := rows.Insert(wantedIndex) as TRowItem;
      rowHeight := (100.0 / rows.Count);

      newRow.SizeStyle := TSizeStyle.ssPercent;
      newRow.Value := rowHeight;

      for rowIndex := 0 to Pred(rows.Count) do
         rows[rowIndex].Value := rowHeight;
   finally
      rows.EndUpdate();
   end;
end;

oder alternativ


Delphi-Quellcode:
procedure TForm17.Button1Click(Sender: TObject);
const
   wantedIndex = 2;
var
   rows:      TRowCollection;
   newRow:      TRowItem;
   rowIndex:   Integer;
   rowHeight:   Single;
begin
   rows := GridPanel1.RowCollection;

   rows.BeginUpdate();
   try
      newRow := rows.Add();
      rowHeight := (100.0 / rows.Count);

      newRow.SizeStyle := TSizeStyle.ssPercent;
      newRow.Value := rowHeight;
      newRow.Index := wantedIndex;

      for rowIndex := 0 to Pred(rows.Count) do
         rows[rowIndex].Value := rowHeight;
   finally
      rows.EndUpdate();
   end;
end;
  Mit Zitat antworten Zitat