Answer the question
In order to leave comments, you need to log in
Delphi. DBGridEh. How to get the data of a cell when hovering over it with the mouse?
When I hover over a DBGridEh cell, I want to receive the record ID and that a button appears on the right side of the cell.
The button is the same for all entries, it is a TPanel in the invis with the OnClick event.
I move the mouse cursor over the cell, the panel moves to the right place, changes the Visible and Enable properties to true, in its click event I process the entry with the ID in the same cell. (The selected entry in DBgridEh does not change).
Found this way:
procedure TFSprav.DBGridEh2MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var
grCoord: TGridCoord;
aGrid: TCrackDBGrid;
NewActiveRecord, oldActiveRecord: integer;
delta: string;
begin
aGrid := TCrackDBGrid(Sender);
grCoord := aGrid.MouseCoord(X, Y);
aGrid.DataSource.DataSet.DisableControls;
oldActiveRecord := aGrid.DataLink.ActiveRecord; // запоминаем текущую строку (отображаемую) не номер записи
newActiveRecord := grCoord.Y - aGrid.DataLink.ActiveRecord; // получаем положение строки на которой наведена мышка.
aGrid.DataLink.MoveBy(newActiveRecord);
delta := aGrid.DataLink.DataSet.FieldByName('Name').AsString;
if grCoord.X > 0 then
begin
caption := delta;
end;
aGrid.DataLink.ActiveRecord := oldActiveRecord; // возвращаем положение к изначальной строке
aGrid.DataSource.DataSet.EnableControls;
end;
Answer the question
In order to leave comments, you need to log in
Well, at the moment MoveBy
DBGridEh2.OnMouseMove := nil
and after manipulations
DBGridEh2.OnMouseMove := DBGridEh2MouseMove
aGrid := TCrackDBGrid(Sender);No need to break DBGridEh.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question