How do I do a proper owner-draw of Full Row Selected TDBGrid when TDBGrid.DefaultDrawing is false?

社会主义新天地 提交于 2019-12-05 07:46:57

You're better off invoking DrawCellHighlight due to the theme support that you'd need to implement yourself. Even though the row number is not provided to OnDrawColumnCell it doesn't look like it's even used by the DefaultDrawColumnCell code so you don't have to try to calculate it internally:

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;
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;
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!