StringGrid中第一列是判断这一行属性的。默认值为“是”,用户单击这格时变为“否”,再单击时变为“是”。现在要求变为“否”,这一整行背景为红色,请问怎么实现?
以下是我写的,但只能改变一格,而不是一行。
procedure TChangeofDataForm.fromStringGridDrawCell(Sender: TObject; ACol,  ARow: Integer; Rect: TRect; State: TGridDrawState);
begin
    if ARow >0 then
      begin
        if fromStringGrid.Cells[Acol,ARow] = '否' then
          begin
            for ACol := 1 to fromStringGrid.ColCount do
              begin
                fromStringGrid.Canvas.Font.Color := clBlack;
                fromStringGrid.Canvas.Brush.Color := clred;
                fromStringGrid.Canvas.TextOut(Rect.Left + 2, Rect.Top + 2,fromStringGrid.Cells[ACol, ARow]);
              end;
          end;
      end;
end;

解决方案 »

  1.   

    先定义 X:INTEGER;
    改:
                for x := 1 to fromStringGrid.ColCount do
                  begin
                    fromStringGrid.Canvas.Font.Color := clBlack;
                    fromStringGrid.Canvas.Brush.Color := clred;
                    fromStringGrid.Canvas.TextOut(Rect.Left + 2, Rect.Top + 2,fromStringGrid.Cells[x, ARow]);
      

  2.   

    procedure TChangeofDataForm.fromStringGridDrawCell(Sender: TObject; ACol,  ARow: Integer; Rect: TRect; State: TGridDrawState);
    begin
        if (ARow >0 ) and (ACol > 0) then
          begin
            if fromStringGrid.Cells[1,ARow] = '否' then   // 第一列为否就着色
              begin
                    fromStringGrid.Canvas.Font.Color := clBlack;
                    fromStringGrid.Canvas.Brush.Color := clred;
                    fromStringGrid.Canvas.TextOut(Rect.Left + 2, Rect.Top + 2,fromStringGrid.Cells[ACol, ARow]);
              end;
          end;
    end;
      

  3.   

    imacih的方法是可行的,你应该更改第一列的cell的值后重新画一下。
    TStringGrid.Repaint
      

  4.   

    http://blog.csdn.net/whbo/articles/232420.aspx
    是dbgrid的颜色操作,你参考下