Font cannot be changed an AdvStringgrid cell with added buttons

Please check the added small project. Font properties of the cells of a TAdvStringgrid with a buttons added do not change (even when buttons are removed). Any idea to cope with this?
Best regards HG Kneip
(Delphi 11.3, VCL UI Pack 13.0.4.0)

image
[ADVStringGrid_Font_Buttons.zip|attachment]
(upload://AaKxBApIhvHzeL2z9aCuzfiAlL7.zip) (91.8 KB)

There seems to be a problem with the attached project.
I cannot download it. Make sure you do NOT include EXE files or other potentially dangerous file types in ZIP attachments.

Here is the simple code. AdvStringGrid with default values..

FILL GRID:
for row := 1 to asg.RowCount -1 do
begin
for col := 0 to asg.ColCount -1 do
begin
if col = 0 then
asg.Cells[col, row] := '+';
if col = 1 then
asg.Cells[col, row] := IntToStr(row);
if col = 2 then
asg.Cells[col, row] := 'Value ' + IntToStr(row);
end;
end;

FONT +:
asg.Font.Size := asg.Font.Size +1;
asg.Canvas.Font.Size := asg.Font.Size; //with or without
asg.AutoSizeRows(true);

ADD BUTTONS:
for row := 1 to asg.RowCount -1 do
asg.AddButton(1, row, 35, 16, 'doc', haRight, vaTop);

I changed your code to make this very visible to

var
  row,col: integer;
begin
  for row := 1 to asg.RowCount -1 do
  begin
  for col := 0 to asg.ColCount -1 do
  begin
  if col = 0 then
  asg.Cells[col, row] := '+';
  if col = 1 then
  asg.Cells[col, row] := IntToStr(row);
  if col = 2 then
  asg.Cells[col, row] := 'Value ' + IntToStr(row);
  end;
  end;

//  FONT +:
  asg.Font.Size := 16;// asg.Font.Size +1;
  asg.Canvas.Font.Size := asg.Font.Size; //with or without
  asg.AutoSizeRows(true);

//  ADD BUTTONS:
  for row := 1 to asg.RowCount -1 do
  asg.AddButton(1, row, 35, 16, 'doc', haRight, vaTop);
end;

and the button font changes too
image

Dear Mr. Fierens. The order of clicking the buttons should be: 1) Fill grid 2) Add buttons 3) Font +. In this order your proposal does not work either. Besides size I also cannot change further font properties. Further ideas? Best regards HG Kneip

When an object gets added to a cell, the cell properties, including the cell font get controlled by what is added to the cell and as such, needs to be changed at that level and not longer the global grid level. You can change the font size of the object added to the cell via grid.FontSizes[col,row]: integer;

Thank you Mr. Fierens. You answer has been very helpful!

1 Like