如何改变DBGrid一行的颜色,当指针在哪一行时,颜色就显示为红色?

解决方案 »

  1.   

    先将DBGrid的option里rowselect设置成true,然后处理DBGrid的DrawColumnCell事件procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    begin
          with   dbgrid1.Canvas   do
          begin
              if (gdSelected in State) then
              begin
                  Brush.Style:=bsClear;
                  Brush.Color:=clblue;
                  FillRect(rect);
                  Font.Color:=clwhite;
                  TextOut(Rect.Left,Rect.Top,Column.Field.DisplayText);
              end;
          end;
    end;
      

  2.   

    procedure TMainForm.DBGrid1DrawColumnCell(Sender: TObject;
      const Rect: TRect; DataCol: Integer; Column: TColumnEh;
      State: TGridDrawState);
    begin
      if not (gdSelected in State) then
      begin
          DBGrid1.Canvas.Font.Color := clRed;
          DBGrid1.DefaultDrawColumnCell(Rect,DataCol,Column,State);
      end;
    end;