Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   StringGrid Zeile hinzufügen (https://www.delphipraxis.net/211764-stringgrid-zeile-hinzufuegen.html)

lucy 31. Okt 2022 07:30

StringGrid Zeile hinzufügen
 
Hallo,
habe hier im Forum schon gesucht, bin aber leider noch nicht fündig geworden.

Zurzeit wird die neue Zeile (im StringGrid) unten angehängt.
Wie kann man die aktuelle Zeile oben im StringGrid einfügen?
So das die älteren Datensätze nach unten geschoben werden.

Code:
procedure TForm1.ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
 var
     MSG, MSG1 : String;
             sl: TStrings;
    i, zaehler : Integer;
 begin
  MSG := Socket.ReceiveText;

  sl := TStringList.Create;
  sl.delimiter := ':';
  sl.DelimitedText := MSG;
   if sl.Strings[0] = 'test' then begin
    Memo1.Lines.Delete(0);
     end else begin
       MSG1 := sl.Strings[0] + ' | ' + sl.Strings[1] + ' | ' + sl.Strings[2] + ' | ' + sl.Strings[3] + ' | ' + sl.Strings[4];
       Memo3.Lines.Add('Status: ' + datetostr(date) + ' | ' + timetostr(time) + ' | ' + Socket.RemoteAddress + ' | ' + 'OnClientRead | ' + MSG1);
       
        i := StringGrid1.RowCount;
         StringGrid1.RowCount := i +1;

         StringGrid1.Cells [0, i] := '';
         StringGrid1.Cells [1, i] := '';
         StringGrid1.Cells [2, i] := IntToStr(zaehler);
         StringGrid1.Cells [3, i] := FormatDateTime ('dd:mm:yyyy', Now);
         StringGrid1.Cells [4, i] := FormatDateTime ('hh:nn:ss', Now);
         StringGrid1.Cells [5, i] := (sl.Strings[3]);

         StringGrid1.ColWidths[0] := 25;
         StringGrid1.ColWidths[1] := 70;
         StringGrid1.ColWidths[2] := 70;
         StringGrid1.ColWidths[3] := 70;
         StringGrid1.ColWidths[4] := 70;
         StringGrid1.ColWidths[5] := 125;
         StringGrid1.ColWidths[6] := 5000;

         StringGrid1.Cells [0,0] := '';
         StringGrid1.Cells [1,0] := '';
         StringGrid1.Cells [2,0] := 'TICKET';
         StringGrid1.Cells [3,0] := 'DATUM';
         StringGrid1.Cells [4,0] := 'ZEIT';
         StringGrid1.Cells [5,0] := 'ID';
         StringGrid1.Cells [6,0] := 'BESCHREIBUNG';
  end;
 end;

zeras 31. Okt 2022 08:07

AW: StringGrid Zeile hinzufügen
 
Mit
Delphi-Quellcode:
StringGrid1.InsertRows()

lucy 14. Nov 2022 18:42

AW: StringGrid Zeile hinzufügen
 
Liste der Anhänge anzeigen (Anzahl: 1)
bekomme es einfach nicht hin?
es werden immer zwei neue Zeilen erzeugt... bzw. eine überschrieben

Delphi-Quellcode:
procedure TForm2.Button1Click(Sender: TObject);
 var
i: integer;
begin
 StringGrid1.RowCount := StringGrid1.RowCount +1;
    for i := StringGrid1.RowCount - 2 downto StringGrid1.FixedRows + 1 do
    begin
     StringGrid1.Rows [i].Assign (StringGrid1.Rows [i -1]);
     StringGrid1.Cells [1, StringGrid1.FixedRows] := FormatDateTime ('dd:mm:yyyy', Now);
     StringGrid1.Cells [2, StringGrid1.FixedRows] := FormatDateTime ('hh:nn:ss', Now);
     StringGrid1.Cells [3, StringGrid1.FixedRows] := ('Log');
 end;
end;

juergen 14. Nov 2022 22:08

AW: StringGrid Zeile hinzufügen
 
Hier in der Delphi-Praxis habe ich das direkt gefunden:
Im Stringgrid oben eine neue Zeile einfügen

Jumpy 15. Nov 2022 13:38

AW: StringGrid Zeile hinzufügen
 
Hast du den Part mal ausserhalb der Schleife probiert, mach ja keinen Sinn innerhalb:

Delphi-Quellcode:
StringGrid1.Cells [1, StringGrid1.FixedRows] := FormatDateTime ('dd:mm:yyyy', Now);
StringGrid1.Cells [2, StringGrid1.FixedRows] := FormatDateTime ('hh:nn:ss', Now);
StringGrid1.Cells [3, StringGrid1.FixedRows] := ('Log');


Alle Zeitangaben in WEZ +1. Es ist jetzt 10:13 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz