点击单元格选择整行,又可编辑单元格

在DBGrid中,怎样才能让我能点击一个单元格选择整行,又可以编辑单元格的内容呢?【hongxing_dl 提供代码】  在设计过程中,有时候数据较大量,field 较多的时候,只是点击单元格可能会对某个field的数据误操作(如数据错行),为此才会想到这个问题,解决办法如下:
    点击单元格就改当前行颜色。这个办法也算是没办法的办法吧!

type
TMyDBGrid=class(TDBGrid);
//////////////////////////////////
//DBGrid1.Options->dgEditing=True
//DBGrid1.Options->dgRowSelect=False
procedure TForm1.DBGrid1DrawColumnCell(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;

测试通过(d7)!

原文地址:https://www.cnblogs.com/martian6125/p/9631542.html