我想在stringgrid中实现一个小功能。
双击stringgrid的其中的某一个小格后,让这个小格的颜色变为红色,怎么实现?

解决方案 »

  1.   

    在双击事件里触发DRAWCELL事件,
    with Stringgrid1 do
    begin
        canvas.brush.color:=clred;
        canvas.fillrect(rect);
    end;
      

  2.   

    楼主这样做好象有点问题哦
    可以这样实现:
    定义一个全局变量:R:TRect;
    在DrawCell事件中R:=Rect;
    再在StringGrid1DblClick中 :
          with StringGrid1 do
         begin
         canvas.Brush.Color:=clred;
         canvas.FillRect(R);
         end;
    就可以了!
      

  3.   

    不知道和DBGrid的方法一样不一样
      

  4.   

    procedure TForm1.StringGrid1DblClick(Sender: TObject);
    Const  pl=3;//调整可能的偏移
    var
       Rect: TRect;
    begin
      with  StringGrid1 do
      begin
        Form1.Repaint;
        Rect.Left := DefaultColWidth*Col+GridLineWidth*pl;
        Rect.Top := DefaultRowHeight*Row+GridLineWidth*pl;
        Rect.Right := DefaultColWidth*(Col+1)+GridLineWidth*pl;
        Rect.Bottom := DefaultRowHeight*(Row+1)+GridLineWidth*pl;
        Canvas.FillRect(Rect);
        Canvas.Brush.Color := clred;
        Canvas.Rectangle(Rect);
      end;
    end;
      

  5.   

    先要在stringGrid的SelectCell事件里选到当前点击的cell
    procedure TfrmTimeIntervalLog.stringGridSelectCell(Sender: TObject; ACol,
      ARow: Integer; var CanSelect: Boolean);
    begin
      if ARow <= 0 then exit;
        intRow := ARow;
        intCol := ACol;
    end;然后再如同楼上所说作颜色改变的操作。