用TDBGridEh表格控件时,怎样得到单元格的坐标?

gzssqx 2003-10-21 01:21:44
我在ColEnter事件中写:
procedure TForm1.DBGridEh1ColEnter(Sender: TObject);
begin
ShowMessage('Row = ' + IntToStr(DBGridEh1.Row) + ' Col = ' +
IntToStr(DBGridEh1.Col) + ' ' +
IntToStr(DBGridEh1.CellRect(DBGridEh1.Row,DBGridEh1.Col).Left));
end;

不管用,那位检查一下,帮忙给个解决办法,谢谢!
...全文
184 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
flfljh 2003-10-21
  • 打赏
  • 举报
回复
关注
47522341 2003-10-21
  • 打赏
  • 举报
回复
楼主要的应该是上面的那个了;
47522341 2003-10-21
  • 打赏
  • 举报
回复
procedure TForm1.DBGridEh1CellClick(Column: TColumnEh);
begin
showmessage(inttostr(dbgrideh1.Row));
showmessage(inttostr(dbgrideh1.SelectedIndex));
end;
HiMrXia 2003-10-21
  • 打赏
  • 举报
回复
procedure TForm1.DBGridEh1ColEnter(Sender: TObject);
var
pLT: TPoint;
pRB: TPoint;
rRect: TRect;
begin
rRect := DBGridEh1.CellRect(DBGridEh1.col, DBGridEh1.row); //反了

pLT := DBGridEh1.ClientToParent(rRect.TopLeft); //用ClientToParent
pRB := DBGridEh1.ClientToParent(rRect.BottomRight); //用法见帮助

Panel1.Left := pLT.X;
Panel1.Top := pRB.Y;

Panel1.Caption := 'Left = ' + IntToStr(pLT.X) + ' Bottom = ' + IntToStr(pRB.Y);

end;
gzssqx 2003-10-21
  • 打赏
  • 举报
回复
outer2000(天外流星):
我照你的测了一下,代码如下:
procedure TForm1.DBGridEh1ColEnter(Sender: TObject);
var
pLT: TPoint;
pRB: TPoint;
rRect: TRect;
begin
rRect := DBGridEh1.CellRect(DBGridEh1.row,DBGridEh1.col);

pLT := DBGridEh1.ClientToScreen(Point(rRect.Left, rRect.Top));
pRB := DBGridEh1.ClientToScreen(Point(rRect.Right, rRect.Bottom));

Panel1.Left := pLT.X;
Panel1.Top := pRB.Y;
end;

Panel1的位置也不知道是按什么规律在动,到处瞎蹦
拜托哪位测一下,我想让Panel1以单元格Left为左边届,贴着单元格下边显示

tanqth(青蛙) :我的方法和你给出贴子中得分那位兄弟的一样
hmzgz81 2003-10-21
  • 打赏
  • 举报
回复
我看不是代码有问题!
tanqth 2003-10-21
  • 打赏
  • 举报
回复
StringGrid1.CellRect(StringGrid1.Col,StringGrid1.Row).Left
StringGrid1.CellRect(StringGrid1.Col,StringGrid1.Row).Top

这是用于StringGrid1的,也可以用于DBGridEh1,
看看
http://expert.csdn.net/Expert/topic/1986/1986064.xml?temp=.1791498
outer2000 2003-10-21
  • 打赏
  • 举报
回复
Translates a given point from client area coordinates to global screen coordinates.

function ClientToScreen(const Point: TPoint): TPoint;

Description

Use ClientToScreen to convert a point whose coordinates are expressed locally to the control to the corresponding point in screen coordinates. In client area coordinates (0, 0) corresponds to the upper left corner of the control's client area. In screen coordinates (0, 0) corresponds to the upper left corner of the screen.

Use ScreenToClient along with ClientToScreen to convert from one control's coordinate system to another control's coordinate system. For example,

P := TargetControl.ScreenToClient(SourceControl.ClientToScreen(P));

converts P from coordinates in SourceControl to coordinates in TargetControl.
gzssqx 2003-10-21
  • 打赏
  • 举报
回复
谢谢楼上的关注,
我是想取该坐标,在该坐标下方弹出一个面板

DBGridEh1.CellRect(DBGridEh1.Row,DBGridEh1.Col).Left得不到正确的单元格坐标,很多单元格都为Left = 0
hmzgz81 2003-10-21
  • 打赏
  • 举报
回复
你要实现什么功能?

我试了你的代码,是好的啊! 有什么问题?
gzssqx 2003-10-21
  • 打赏
  • 举报
回复

自己UP

5,379

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧