10

I'm just trying to use delphi XE, before that I've been a big fan of Delphi7.
I see the new dbgrid allows to use themed and gradient styles.

I'm using gradient and set rowselect, it has a property for gradient-start and -end for the column header.
But where is the property to set the selected color ?
It's strange because the color doesn't match, selected color is always a blue gradient.

I can do it with customdraw, I just want to know if there is anyway to change it without custom drawing.

dataol
  • 891
  • 3
  • 19
  • 42
coliv_aja
  • 101
  • 1
  • 4
  • 4
    `sory,my bad english ;)` Never apologize for that. Only 60 million people are native English speakers, the rest of us just struggle. _Feels odd saying this whilst using US_EN spelling_ – Johan Sep 24 '11 at 05:45
  • Perhaps it comes from the OS, as in clHighlight? – Ondrej Kelle Sep 24 '11 at 13:03

1 Answers1

1

The selected color comes from the OS.
There it's coded as clHighlight.

You cannot change it as such, but you can subclass the dbgrid and override the DrawCell method.
Or even easier add a onDrawCell eventhandler.

procedure TForm1.DBGrid1DrawCell(Sender: TObject, const Rect: TRect; Field: TField;  State: TGridDrawState); 
var
  index: Integer;
begin
  if not(gdSelected in State) then DefaultDrawCell(Rect, Field, State)
  else begin 
    index := ARow * DBGrid1.ColCount + ACol;
    DBGrid1.Canvas.Brush.Color := clYellow; <<-- some color  
    DBGrid1.Canvas.FillRect(Rect);
    if (gdFocused in State) then begin
      DBGrid1.Canvas.DrawFocusRect(Rect);
    end;
    ImageList1.Draw(DBGrid1.Canvas,Rect.Left,Rect.Top,index, True);
end;
Johan
  • 71,222
  • 23
  • 174
  • 298