2
votes

I am trying to change the color of a Title cell in a particular column of a DBGRID component in Delphi XE6. I used to paint column title when the grid was sorted by that certain column.

DBGRID1.Columns[1].Title.Color := clBlue;

Is this possible? Or is there a better way how to highlight sorted column?

1
Did you try DBGrid1.Columns[1].Title.Font.Color := clBlue; ?Andy_D
Can you clarify what you mean by "change the color of a Title cell"? Do you mean the font color, or the color of the actual cell (column header) itself?Ken White
Generally a little glyph is drawn to indicate key columns. Requires some code. If I remember correct JvDBGrid had it by default.Sertac Akyuz
By color of a Title cell I mean background color of the actual column header. DBGRID1.Columns[1].Title.Color := clBlue; works in Delphi 2006 but not in XE6. Looks like it's because VCL Styles. DBGrid1.Columns[1].Title.Font.Color := clBlue; works. But diferent the font color is not as visible as a diferent background color. My users complain that they have trouble identifying the current column. I tryied glyphs in JvDbGrid but my users are used to different background color and they complain that different font color and glyphs are not enough.user3401364
Please edit your question and add the relevant information there to clarify your question. Burying it in a comment (especially one you've jumbled up with other information addressed to several people's questions) makes it almost impossible for readers of your question to see, and the information is relevant to any answer given. Thanks.Ken White

1 Answers

1
votes

try override procedure TCustomDBGrid.DrawCellBackground to force background color of title:

procedure TMyDBGrid.DrawCellBackground(const ARect: TRect; AColor: TColor; AState: TGridDrawState; ACol, ARow: integer);
begin
  if (FLastSortedColumnIdx = ACol) and (ACol >= 0) and (ARow = -1) then
    AColor := Columns[ACol].Title.Color;

  inherited;
end;

FLastSortedColumnIdx is field where you have Column.Index of sorted column stored.

Should work in Delphi XE3.