在Delphi 2010中,有什么方法可以检测dgRowSelect
设置为True时单击了哪个单元格?
通常我会使用OnCellClick(Column: TColumn)
事件处理程序,但这不能按预期工作。使用dgRowSelect = False
,此过程将传递已单击的列,但使用dgRowSelect = True
此过程将传递到第一列,无论单击哪个列。
我无法解决调用OnCellClick
传递TColumn
参数的代码的位置,如果我发现我可能能够解决如何修复这种奇怪的行为。
答案 0 :(得分:14)
您可以使用鼠标坐标来获取列。调用TDBGrid.MouseCoord
后,返回的TGridCoord.X
包含列号,Y
包含行(当然,您已经拥有):
procedure TForm1.DBGrid1CellClick(Column: TColumn);
var
Pt: TPoint;
Coord: TGridCoord;
ClickCol: Integer;
begin
Pt := DBGrid1.ScreenToClient(Mouse.CursorPos);
Coord := DBGrid1.MouseCoord(Pt.X, Pt.Y);
ClickCol := Coord.X;
ShowMessage('You clicked column ' + IntToStr(ClickCol));
end;
documentation中TGridCoord
的更多信息。
使用与your previous question的答案相同的应用程序进行测试。