procedure TForm1.DBGrid1DrawDataCell(Sender: TObject; const Rect: TRect; Field: TField; State: TGridDrawState); begin if (Rect.Top = TStringGrid(DBGrid1).CellRect(TStringGrid(DBGrid1).col,TStringGrid(DBGrid1).row).top) and (not (gdFocused in State)) then Dbgrid1.Canvas.Brush.Color := clRed; DBGrid1.DefaultDrawDataCell(Rect, Field, State); end;
显示选中行的颜色可以用设置dbgrid的option->rowselecded来实现;
搞定!设置Dbgrid的DBGrid1DrawDataCell事件中添加如下代码: dbgrid1.Canvas.Font.Color:=clgreen;if gdSelected in state thenSetBkColor(dbgrid1.canvas.handle,clred)elsesetbkcolor(dbgrid1.canvas.handle,clwhite);dbgrid1.Canvas.TextRect(rect,0,0,field.AsString);dbgrid1.Canvas.Textout(rect.Left,rect.Top,field.AsString);
Field: TField; State: TGridDrawState);
begin
if (Rect.Top = TStringGrid(DBGrid1).CellRect(TStringGrid(DBGrid1).col,TStringGrid(DBGrid1).row).top) and (not (gdFocused in State)) then
Dbgrid1.Canvas.Brush.Color := clRed;
DBGrid1.DefaultDrawDataCell(Rect, Field, State);
end;
dbgrid1.Canvas.Font.Color:=clgreen;if gdSelected in state thenSetBkColor(dbgrid1.canvas.handle,clred)elsesetbkcolor(dbgrid1.canvas.handle,clwhite);dbgrid1.Canvas.TextRect(rect,0,0,field.AsString);dbgrid1.Canvas.Textout(rect.Left,rect.Top,field.AsString);