stringgrid中值如下  1     2      3  2     4      5  6     4      6我点中其中的一个2的cell  ,该cell与另外一个2的cell同变成一个颜色,点到其他cell上,两个cell还变成原来的颜色要求:不要重新刷新,上面只是我举的例子,实际过程中cell比较多,刷新的话会很慢

解决方案 »

  1.   

    要求:不要重新刷新,上面只是我举的例子,实际过程中cell比较多,刷新的话会很慢-----------------
    不刷新能达到你要求就怪了 
      

  2.   

    如果不刷新全部的话 建议应该把stringgrid拆成若干个小的单元 
    然后找出值相同的进行变色 其他的不用变
      

  3.   

    不能刷新,只能重绘了
    Canvas.Invalidate;
      

  4.   


    procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
      if StringGrid1.Cells[ACol,ARow] = '选中的值' then
      begin
        StringGrid1.Canvas.Brush.Color := clRed;
        StringGrid1.Canvas.FillRect(Rect);
        StringGrid1.Canvas.Font.Color := clWhite;
        StringGrid1.Canvas.TextOut(Rect.Left,Rect.Top,StringGrid1.Cells[ACol,ARow]);
      end;
    end;
      

  5.   


    //改改楼上的procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
      var CanSelect: Boolean);
    begin
      Caption:= StringGrid1.Cells[ACol,ARow];
      StringGrid1.Refresh;
    end;procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
      if StringGrid1.Cells[ACol,ARow] = Caption then
      begin
        StringGrid1.Canvas.Brush.Color := clRed;
        StringGrid1.Canvas.FillRect(Rect);
        StringGrid1.Canvas.Font.Color := clWhite;
      end else
      begin
        StringGrid1.Canvas.Brush.Color := clWhite;
        StringGrid1.Canvas.FillRect(Rect);
        StringGrid1.Canvas.Font.Color := clBlack;
      end;
      StringGrid1.Canvas.TextOut(Rect.Left,Rect.Top,StringGrid1.Cells[ACol,ARow]);
    end;