Delphi tdbgrideh 如何用鼠标选一行记录
要使用鼠标选中一行记录,可以使用TDBGridEh的事件OnCellClick或OnMouseDown来实现。
在OnCellClick事件中,可以通过以下代码来获取选中行的索引:
procedure TForm1.DBGridEh1CellClick(Column: TColumnEh);
begin
DBGridEh1.SelectedRows.Clear;
DBGridEh1.SelectedRows.CurrentRowSelected := True;
end;
在OnMouseDown事件中,可以通过以下代码来获取选中行的索引:
procedure TForm1.DBGridEh1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
GridCoord: TGridCoord;
begin
GridCoord := DBGridEh1.MouseCoord(X, Y);
if (GridCoord.Y > 0) and (Button = mbLeft) then
begin
DBGridEh1.SelectedRows.Clear;
DBGridEh1.SelectedRows.CurrentRowSelected := True;
end;
end;
以上代码中,DBGridEh1是一个TDBGridEh控件,SelectedRows是一个TBookmarkList对象,用于存储选中行的书签。设置SelectedRows.CurrentRowSelected为True,可以选中当前行
原文地址: https://www.cveoy.top/t/topic/inrl 著作权归作者所有。请勿转载和采集!