在设计过程中,有时候数据较大量,field 较多的时候,只是点击单元格可能会对某个field的数据误操作(如数据错行),为此才会想到这个问题,解决办法如下:点击单元格就改当前行颜色。

首先DBGRID的属性做好下设置(其实也是DBGRID默认的属性)

DBGrid1->Options->dgEditing=True
DBGrid1->Options->dgRowSelect=False


一、先在implementation前做如下定义
type
  TMyDBGrid=class(TDBGrid);


二、在DBGrid的OnDrawColumnCell操作
procedure Tfrm_hetong.DBGrid2DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
begin
  with TMyDBGrid(Sender) do
    begin
      if DataLink.ActiveRecord=Row-1 then
        begin
          Canvas.Font.Color:=clWhite;
          Canvas.Brush.Color:=$00800040;
        end
      else
        begin
          Canvas.Brush.Color:=Color;
          Canvas.Font.Color:=Font.Color;
        end;
      DefaultDrawColumnCell(Rect,DataCol,Column,State);
    end;
end;

相关文章:

  • 2022-12-23
  • 2021-07-03
  • 2022-12-23
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-29
  • 2022-12-23
  • 2022-03-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案