我想判断如果stringgrid中某个单元格的值大于10则让这个单元格颜色变成红色,请问如何实现,请给代码。

解决方案 »

  1.   

    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
      if (stringgrid1.Cells[acol,arow] <> '') and (strtoint(stringgrid1.Cells[acol,arow]) > 0) then
      begin
        stringgrid1.Canvas.Brush.Color:= clRed;
        stringgrid1.Canvas.FillRect(rect);
      end;
    end;
      

  2.   

    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
       try
         if trim(StringGrid1.Cells[Acol,Arow])<>'' then
         if StrToint(StringGrid1.Cells[Acol,Arow])>10 then
         begin
           StringGrid1.Canvas.Brush.Color:=clred;
           StringGrid1.Canvas.TextRect(Rect,Rect.Left,Rect.Top,StringGrid1.Cells[Acol,Arow]);
         end;
       except;
       end;
    end;
      

  3.   

    修改一下
    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
      if (stringgrid1.Cells[acol,arow] <> '') and (strtoint(stringgrid1.Cells[acol,arow]) > 0) then
      begin
        stringgrid1.Canvas.Brush.Color:= clRed;
        stringgrid1.Canvas.FillRect(rect);
        stringgrid1.Canvas.TextOut(rect.Left+1,rect.Top+5,stringgrid1.Cells[acol,arow]);
      end;
    end;
      

  4.   

    修改一下
    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
      if (stringgrid1.Cells[acol,arow] <> '') and (strtoint(stringgrid1.Cells[acol,arow]) > 10) then
      begin
        stringgrid1.Canvas.Brush.Color:= clRed;
        stringgrid1.Canvas.FillRect(rect);
        stringgrid1.Canvas.TextOut(rect.Left+1,rect.Top+5,stringgrid1.Cells[acol,arow]);
      end;
    end;
      

  5.   

    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    var TextB : String;
    begin
      TextA := stringgrid1.Cells[ACol,ARow];
      if TextA = '' then
      begin
        stringgrid1.Canvas.Brush.Color := $00F5F5F5;
        stringgrid1.Canvas.FillRect(Rect);
      end else if TextA > '10' then
      begin
        stringgrid1.Canvas.Brush.Color:= clRed;
        stringgrid1.Canvas.FillRect(rect);
        stringgrid1.Canvas.TextOut(rect.Left+1,rect.Top+5,stringgrid1.Cells[acol,arow]);
      end;
    end