您的位置:首页 > 其它

在DBGrid中,单击单元格选择整行,双击又可编辑单元格

2017-09-17 22:53 253 查看

在设计过程中,有时候数据较大量,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;

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: