When the user selects the header of my grid, I would like to bold the column header of the grid.
I use the following code to achieve this:
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var I: Integer;
begin
//Prevent multiple clicks!
if fsBold in Column.Title.Font.Style then
Exit;
for I:= 0 to Column.Collection.Count-1 do
(Column.Collection.Items[I] as TColumn)
.Title.Font.Style := [];
Column.Title.Font.Style := [fsBold];
end;
This code is working fine.
In the OnFormCreate
I've defined the following header height:
type
DBGridHack = class(TDBGrid);
procedure TForm1.FormCreate(Sender: TObject);
begin
DBGridHack(DBGrid1).RowHeights[0] := 45;
end;
When I click in the Title, the procedure InternalLayout.MeasureTitleHeights
changes the size back to the original.
Thus, every time I change the font style I need to redefine the value for RowHeight[0]
.
The code would look like this:
procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var I: Integer;
begin
//Prevent multiple clicks!
if fsBold in Column.Title.Font.Style then
Exit;
for I:= 0 to Column.Collection.Count-1 do
(Column.Collection.Items[I] as TColumn)
.Title.Font.Style := [];
Column.Title.Font.Style := [fsBold];
//Every time!!
DBGridHack(DBGrid1).RowHeights[0] := 45;
end;
There is another issue when the user redefine the Column's width, in this case the RowHeight[0]
also returns to the original value. The only way I imagine to solve this, is to inherit DBGrid and override ColWidthsChanged
, but how much more methods will I have to override?
Why this happens?
Is this a bug, or is my code bugged?
Is there a way to workaround this?
In a simple question.
How to FIX a value to the DBGrid's header heigth?