DELPHI中的DBGRID的鼠标移入和移出问题
DBGRIDEH,我想再鼠标移动再某一行时,弹出一个提示,提示显示这条记录的ID比如有三行:IDMcBH1测试1C012测试2C023测试3C03鼠标移动到第一个行,sh...
DBGRIDEH,我想再鼠标移动再某一行时,弹出一个提示,提示显示这条记录的ID
比如有三行:
ID Mc BH
1 测试1 C01
2 测试2 C02
3 测试3 C03
鼠标移动到第一个行,show出来1
第二行SHOW出来2
第三行SHOW出来3
快啊 展开
比如有三行:
ID Mc BH
1 测试1 C01
2 测试2 C02
3 测试3 C03
鼠标移动到第一个行,show出来1
第二行SHOW出来2
第三行SHOW出来3
快啊 展开
1个回答
2013-11-20
展开全部
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;
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;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询