1.在TCustomDBGridEh对象新建两个public函数
function TCustomDBGridEh.GetActiveRecord():Integer;
begin
Result:=FDataLink.GetActiveRecord;
end;
procedure TCustomDBGridEh.SetActiveRecord(nActiveRecord: Integer);
begin
FDataLink.SetActiveRecord(nActiveRecord);
end;
2.在MouseMove时,事件这般处理:
procedure TfrmPaiBan.DBGrdPBMouseMove(Sender: TObject; Shift: TShiftState;
X, Y: Integer);
var
oCoord: TGridCoord;
nOldRecNo: Integer;
begin
oCoord:=DBGrdPB.MouseCoord(x,y);
if DBGrdPB.DataSource.DataSet.Active and(not DBGrdPB.DataSource.DataSet.IsEmpty) then
if (oCoord.Y>=1)and(oCoord.Y<=DBGrdPB.VisibleRowCount)and(oCoord.X>=1)and(oCoord.X<=DBGrdPB.Columns.Count) then
begin
try
nOldRecNo:=DBGrdPB.GetActiveRecord;
DBGrdPB.SetActiveRecord(oCoord.Y-1);
//do some thing
finally
DBGrdPB.SetActiveRecord(nOldRecNo);
end;
end;
end;