I'm trying to programatically highlight the current cell in a TDBGrid descendant. If I do DBGrid.SetFocus, I get the combo box arrow below, which isn't sufficiently highlighted for me.
EDIT:
I'm already doing DBGrid.SelectedField := DataSource.FieldByName('Name');
To bring the user's attention more to the region in question, I set:
DBGrid.Columns[x].Title.Font.Style := [fsbold, fsunderline];
And I set a timer that after five seconds does:
DBGrid.Columns[x].Title.Font.Style := [];
What's weird is that after the time goes off, the cell becomes blue (as shown below.) That's the highlight I wanted in the first place. But I don't know enough about grids to know how to get that directly.
My question: how to I get a grid cell highlighted as in the blue example below? I've never done anything like this before, so I'm a bit lost. Is this an InPlaceEditor function?
I'm using a descendant of TDBGrid, so I'm not sure if the behavior I'm seeing is intrinsic to TDBGrid, or just in the descendant (in which case I know my question can't be answered here. )

I've been using the following (D2007) using the DBGrid: OnDrawColumnCell event.
procedure TForm1.DBGridDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
//Make the column blue if the title is bold
if (fsBold in Column.Title.Font.Style) then
TDBGrid(Sender).Canvas.Brush.Color := $00fff0e1;
//Set the selected row to white/bold text on blue background
if (gdSelected in State) then
begin
TDBGrid(Sender).Canvas.Brush.Color := clHighlight;
TDBGrid(Sender).Canvas.Font.Style := Font.Style + [fsBold];
TDBGrid(Sender).Canvas.Font.Color := clHighlightText;
end;
//Update the grid
TDBGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With