单步调试一下
if (gdselected in state) and selectY then //当点后SelectY为true
后边的语句有没有执行
selectY是不是在第一次点击时为true了

解决方案 »

  1.   

    if (gdfocused in state) and selectY then //改改试试
      

  2.   

    你的太长了,懒的看!
    这里正好有个斑马线的,你自己看看
    大同小异……unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      Db, Grids, DBGrids, DBTables;type
      TForm1 = class(TForm)
        Table1: TTable;
        DBGrid1: TDBGrid;
        DataSource1: TDataSource;
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure FormCreate(Sender: TObject);
        procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
          DataCol: Integer; Column: TColumn; State: TGridDrawState);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      Action:=CaFree;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      Table1.DatabaseName:='test';
      Table1.TableName:='test.db';
      Table1.Active:=True;
      Datasource1.DataSet:=Table1;
      DBGrid1.DataSource:=DataSource1;
      DBGrid1.Align:=alClient;
    end;procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
      Case Datacol Mod 2=0 of
      True:DBGrid1.Canvas.Brush.Color:=CLRed;
      False:DBGrid1.Canvas.Brush.Color:=CLGreen;
      end;
      if ((State=[GdSelected]) or (State=[GdSelected,GdFocused])) then
      DBGrid1.Canvas.Brush.Color:=CLBlue;
      DBGrid1.DefaultDrawColumnCell(Rect,Datacol,Column,State);
    end;end.
      

  3.   

    在Delphi中随意控制DBGrid每一行的颜色  
        有个问题是在Delphi中使用DBGrid时,如何让DBGrid中每一行颜色按照用户自己的意愿控制。最初看到这个问题时,我们以为非常非常简单,所以马上动手准备解决它。结果却发现不是那么回事,传统方法根本不能发挥作用。在电脑面前一直坐到凌晨4点,不断地调试,幸运地是凭借平时积累的一点编程经验,终于找到了开门的匙钥。现将它充公,供大家享用。 1、 数据表的建立 2、程序设置;
    procedure Tinfo.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
            if query1.FieldByName(’all’).asstring>40’ then
            begin
                    dbgrid1.Canvas.Font.Color:=clred;
                    dbgrid1.Canvas.Brush.color:=clyellow;
            end
            else
            begin
                    dbgrid1.Canvas.Font.Color:=clblue;
                    dbgrid1.Canvas.Brush.color:=clyellow;
                    end;
     
            dbgrid1.DefaultDrawColumnCell(rect,datacol,column,state);
    end;
     
      

  4.   

    晕………
    竟然忘了Refresh
    散分~~