如何在StringGrid当前行第一列也像DBGrid样标出箭头呢?

解决方案 »

  1.   

    你可以从TStringGrid派生一个子类,在子类中当发生进入单元格事件时,在该行第0列自己显示一个箭头。
      

  2.   

    箭头怎么上去,我在OnDrawCell中试过,却无法确定当前行位置?
      

  3.   

    const
      MY_DRAWCELL = WM_USER + 10;type
      TForm1 = class(TForm)
        StringGrid1: TStringGrid;
        procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
          Rect: TRect; State: TGridDrawState);
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
        procedure MyDrawCell(var Msg: TMessage); message MY_DRAWCELL;
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    begin
      if ARow = TStringGrid(Sender).Row then
        PostMessage(Handle, MY_DRAWCELL, Rect.Top, 0);
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      StringGrid1.DefaultRowHeight := 17;
      StringGrid1.ColWidths[0] := 11;
    end;procedure TForm1.MyDrawCell(var Msg: TMessage);
    const
      {$J+}vWParam: DWORD = 0;{$J-}
    begin
      with StringGrid1.Canvas, Msg do
      begin
        ///////Begin 清除上一次的三角
        Pen.Color := clBtnFace;
        Brush.Color := clBtnFace;
        Polygon([
          Point(3, vWParam + 3),
          Point(8, vWParam + 8),
          Point(3, vWParam + 13)
        ]);
        ///////End 清除上一次的三角    Pen.Color := clBlack;
        Brush.Color := clBlack;
        Polygon([
          Point(3, WParam + 3),
          Point(8, WParam + 8),
          Point(3, WParam + 13)
        ]);
        vWParam := WParam;
      end;
    end;