简体   繁体   中英

DBGRID Columns Title Color

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?

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.

Well, If I understand your question,all you need to do is to change the DBGrid DrawingStyle properity to gdsGradient & then change the gradentEndColor & gradentStartColor to be the same color..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM