Recent

Author Topic: StringGrid Clear?  (Read 552 times)

pentilisea

  • Guest
StringGrid Clear?
« on: March 11, 2023, 02:47:38 pm »
Hi again,
getting along with StringGrid fine although...

I configured StringGrid1 with the Object Inspector

The StringGrid displays my diverse calculation. All good.

Before loading next file I clear all Edits and so on.

When I do StringGrid1.Clear, it clears fine, but I can't
restore the original settings I did with Object Inspector.

The following lines leaves the first row0 (?) with titles ok,
loding new file OK, but it does not write again the results into
Row 1 - etc...

Code: Pascal  [Select][+][-]
  1. for c := spins downto 0 do begin
  2.   StringGrid1.DeleteRow(1);
  3.   StringGrid1.Refresh;
  4.   end;

The Grid is configured to have 100 rows to start with.

Well, how do I clear,clean or empty the written rows and start
again with the original code? (which of course fails after a StringGrid1.Clear event)

Code: Pascal  [Select][+][-]
  1.    StringGrid1.Cells[1, spins] := Edit1.text;
  2.    StringGrid1.Cells[2, spins] := inttostr(spins);
  3.    StringGrid1.Cells[3, spins] := IntToStr(beton);
  4.    StringGrid1.Cells[4, spins] := IntToStr(wager);
  5.    StringGrid1.Cells[5, spins] := IntToStr(loss);
  6.    StringGrid1.Cells[6, spins] := IntToStr(win);
  7.    StringGrid1.Cells[7, spins] := IntToStr(budget);
  8.    StringGrid1.Cells[8, spins] := mode;
  9.    StringGrid1.Cells[9, spins] := Label1.Caption;
  10.    StringGrid1.Refresh;

Thanks for your consideration and time.
   For better understanding see attachments.
   
   Klaus     




cdbc

  • Hero Member
  • *****
  • Posts: 995
    • http://www.cdbc.dk
Re: StringGrid Clear?
« Reply #1 on: March 12, 2023, 09:20:00 am »
Hi
Fwiw, I've got three utility functions to do that:
Code: Pascal  [Select][+][-]
  1. - procedure CreateGridHeaders(aGrid: TStringGrid;ColHeaders: array of string;ColWidths: IntegerArray);
  2. - procedure ClearGrid(aGrid: TStringGrid;aSaveHeaders: boolean = true);
  3. - procedure PopulateGrid(aGrid: TStringGrid;anObject: TYourDataObject);
Mind you I am a lazy bast***  :D  Can't be bothered to write the same over and over again... Remember, RowCount is your friend  ;)
Regards Benny
« Last Edit: March 12, 2023, 11:25:19 am by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

 

TinyPortal © 2005-2018