怎样得到 DBGrid 选中的单元格 的 Left,Top 位置???希望不要用事件得到.

解决方案 »

  1.   

    问:
      已经设置  焦点.
      如何得到  焦点的 位置,
      而不是光标的位置 GetCursorPos;
      

  2.   

    procedure TForm1.SpeedButton1Click(Sender: TObject);
    var rect:Trect;
    begin  rect:=TStringGrid(dbgrid1).CellRect(TStringGrid(dbgrid1).Selection.Left,
      TStringGrid(dbgrid1).Selection.Top);  self.Caption:=inttostr(rect.Left)+','+inttostr(rect.Top);
    end;
      

  3.   

    楼上的转换太过危险了吧,DBGrid并不是TStringGrid的子类呀,其不是让DBGrid“任人为父”??
    ^_^,标准做法如下,他可以返回对应行列的矩形区域坐标。
    type
      TMyGrid=class(TCustomGrid);
    procedure TForm1.Button1Click(Sender: TObject);
    var
      cellRect:TRect;
    begin
      cellRect:=TMyGrid(DBGrid1).CellRect(1,1);
    end;
      

  4.   

    同意wizardqi(男巫)的意见:)
    而且TMyGrid=class(TCustomGrid);这一句巧妙的解决了调用TCustomGrid保护成员的问题。
      

  5.   

    1、使用MouseMove事件获取光标位置(x,y)。
    2、用DBGrid.MouseCoord(x,y).X可取得列号,用DBGrid.MouseCoord(x,y).Y可取得行号。