I am running Lazarus v0.9.30 (32 bit compiler).
This question is an extension of a previous question of mine.
The previous question revolved around how to change the orientation of text in the TGridColumns objects that I loaded at runtime into a standard TStringGrid. The solution involved overriding the DrawCellText event of the string grid.
My question is this. When I attempt to load the TStringGrid what I find is that the text orientation remains the same but the column cell height changes back to the default height.
The code I use to load the grid is shown below.
procedure TTmMainForm.vLoadWorldScoutGrid;
var
aMember : TTmMember;
anIndex1: integer;
anIndex2: integer;
begin
//Clear the string grid and set the row count to 1 to take into account the fixed row.
SgWorldScout.Clear;
SgWorldScout.RowCount := 1;
for anIndex1 := 0 to Pred(FManager.Members.Count) do
begin
//Add a new row to the string grid.
SgMembers.RowCount := SgMembers.RowCount 1;
//Get the TTmMember object from the collection.
aMember := TTmMember(FManager.Members.Items[anIndex1]);
//Populate the row cells in the string grid.
SgMembers.Cells[0, SgMembers.RowCount - 1] := aMember.stMemberNumber;
SgMembers.Cells[1, SgMembers.RowCount - 1] := aMember.stPatrol;
SgMembers.Cells[2, SgMembers.RowCount - 1] := aMember.stSurname;
SgMembers.Cells[3, SgMembers.RowCount - 1] := aMember.stFirstName;
//Add the TTmMember object to every row cell.
for anIndex2 := 0 to SgMembers.ColCount - 1 do
SgMembers.Objects[anIndex2, SgMembers.RowCount - 1] := aMember;
end; {for}}
vSetWorldScoutGridPushbuttons;
end;
I suspect that when I call 'SgWorldScout.Clear' that the properties of the string grid cells may get reset / modified as the default DrawCellText event gets called, which would explain the change in cell height. Not sure why the text orientation doesn't change either. Would someone be able to explain the behaviour of the DrawCellText event and why I am seeing this?
CodePudding user response:
The Clear
sets the RowCount
and ColCount
to 0 as you suspected. Then it's quite logical that the RowHeights
is cleared too, because when you have RowCount
set to 0 there are no heights to store. If you want to clear and add only the non fixed rows then simply set only the RowCount
to 1 without clearing the whole grid. So modify your code this way:
procedure TTmMainForm.vLoadWorldScoutGrid;
var
aMember : TTmMember;
anIndex1: integer;
anIndex2: integer;
begin
// set the row count to 1 to keep the fixed row along with its settings
SgWorldScout.RowCount := 1;
for anIndex1 := 0 to Pred(FManager.Members.Count) do
...
end;