Click here to Skip to main content
15,867,330 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would like to clear a string grid when a click on a certain button.Without Changing the properties off the stringgird

What I have tried:

procedure TfrmMain.pnlNewClick(Sender: TObject);
var
i: Integer;
begin
for i := 0 to sgdDisplay.ColCount - 1 do
sgdDisplay.Cols[i].Clear;

However this does clear the string grid to some extent but if the string grids columns and rows was previously filled some blank rows and columns are visible when you clear the string gird. Try this code and see for yourself .Thank you
Posted
Updated 26-Dec-21 2:07am
v2
Comments
0x01AA 24-Dec-21 9:56am    
Not clear for me what the problem is. But in case you like to reset the rows this sgdDisplay.RowCount := 1; will maybe help ;)
Mickyle Govender 24-Dec-21 14:39pm    
Thanks for the advice but,However this clears the stringgirds row it isn't what I'm looking.I looking for a clear that will still keep the same number of rows and columns.
0x01AA 25-Dec-21 12:48pm    
Yes, but you can save the row count value, set it to 1 and afterwards set back to the saved value.
Mickyle Govender 25-Dec-21 15:43pm    
Thank you.Will do

1 solution

Try this:
var OldRowCount: integer;
OldRowCount:= sgdDisplay.RowCount;
sgdDisplay.RowCount:= sgdDisplay.FixedRows;
sgdDisplay.RowCount:= OldRowCount;
I hope it helps.
 
Share this answer
 
v6
Comments
0x01AA 26-Dec-21 8:19am    
Sorry for the frequent updates. I'm not familiar with Pascal ;)
Mickyle Govender 26-Dec-21 12:01pm    
Hi tried your solution, doesn't clear string grid,Maybe im doing something wrong :(
0x01AA 26-Dec-21 13:03pm    
Strange. The code I translated from c++ (from @Gambit, the real reference for borland stuff) to Pascal.
What Delphi version are you using? Latest versions do also support TStingGrid::Clean and TStingGrid::Clear
Mickyle Govender 26-Dec-21 13:09pm    
I'm a IT high school student,we only use Delphi 2010,Yeah the old stuff...
0x01AA 26-Dec-21 13:13pm    
Coming back to 'Hi tried your solution, doesn't clear string grid,...'
Does it mean you see the old values after that?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900