How to make the correct drawer of all selected TDBGrid when TDBGrid.DefaultDrawing is false?

When you have a TDBGrid, full row selection and always show the selection, even if it is not focused, and you want to use it completely, you have the selection of the outdated event OnDrawDataCell, and the new event DrawColumnCell, I selected the latter and try the following:

procedure TDbGridTestForm.mygridDrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if  gdSelected in State then begin
      //      mygrid.DrawCellHighlight(Rect, State, Col, Row);
  mygrid.Canvas.Brush.Color := clHighlight;
  mygrid.Canvas.Font.Color := clHighlightText;
  mygrid.Canvas.FillRect(Rect);
  end;


  mygrid.DefaultDrawColumnCell(Rect, DataCol, Column, State);

end;

And what drives me crazy is that the focus indicator (highlight color and focus rectangle) is not drawn with the DefaultDrawColumnCell code, and I'm sure I should call DrawCellHighlight instead of doing the FillRect hack that I do above ,

DefaultDrawing, ( ), , ( gdSelected).

DBGrids.pas DefaultDrawColumnCell , . , , . , Grids.pas, DBGrids.pas, . , DrawCellHighlight ( ) Col Row, TCustomGrid.DrawCellHighlight, .

, , . NOte, DefaultDrawing , , , , . TCustomGrid.DrawCellHighlight( , ), .

+5
2

DrawCellHighlight - , . , OnDrawColumnCell, DefaultDrawColumnCell, :

type
  tHackGrid = class(tDBGrid);

procedure TTDbGridTestForm.myGridDrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if gdSelected in State then begin
    tHackGrid(mygrid).DrawCellHighlight(Rect, State, Column.Index, 0);
  end;
  mygrid.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
+4
type
  tHackGrid = class(tDBGrid);

procedure MyForm.MyDbGridDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn; State: TGridDrawState);
var ImageIndex: integer;
begin
  if gdSelected in State
  then tHackGrid(Sender).DrawCellHighlight(Rect, State, Column.Index, 0)
  else tHackGrid(Sender).DrawCellBackground(Rect, Column.Color, State, Column.Index, 0);
  TDbGrid(Sender).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
0

All Articles