方法一:
procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
lGridCoord: TGridCoord;
iTemp, jTemp: Integer;
begin
lGridCoord := DBGrid1.MouseCoord(X,Y);
if(lGridCoord.X <= 0) or (lGridCoord.Y <= 0) then Exit;
ADOQuery1.DisableControls;
iTemp := lGridCoord.Y - ADOQuery1.RecNo;
ADOQuery1.MoveBy(iTemp);
//if (...) then //想上下或左右移动一行或一列(即移动一个单元格时)时才执行以下几条语句,该怎么写?
begin
DBGrid1.ShowHint := True;
DBGrid1.Hint := DBGrid1.Columns.Items[lGridCoord.X - 1].Field.DisplayText;
//Application.ActivateHint(Point(Rect.Left, Rect.Top)); //怎么取得鼠标所在行、列(即 lGridCoord )的 Rect 值?我想在鼠标所在那个单元格里 Hint 显示该单元格的值
end;
ADOQuery1.MoveBy(-iTemp);
ADOQuery1.EnableControls;
end;
方法二:
...
private
fGridCoord: TGridCoord;
{ Private declarations }
...
procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
lGridCoord: TGridCoord;
begin
lGridCoord := DBGrid1.MouseCoord(X, Y);
if(lGridCoord.X <= 0) or (lGridCoord.Y <= 0) then Exit;
fGridCoord := lGridCoord;
DBGrid1.Refresh;
end;
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
DataCol: Integer; Column: TColumn; State: TGridDrawState);
var
lGridCoord: TGridCoord;
begin
lGridCoord := TDBGrid(Sender).MouseCoord(Rect.Left, Rect.Top);
if (fGridCoord.X = lGridCoord.X) and (fGridCoord.Y = lGridCoord.Y) then //and (...),想上下或左右移动一行或一列(即移动一个单元格时)时才执行以下几条语句,该怎么写?
begin
DBGrid1.ShowHint := True;
DBGrid1.Hint := Column.Field.DisplayText;
Application.ActivateHint(Point(Rect.Left + 6, Rect.Top + 12));
end;
end;
哪种方法好呢?