Reputation: 59
Is there a way to capture name of title with mouse move over Dbgrids title?
Idea is to make title name visible only when cursor is moved over title's field.
Tnx in advance.
Upvotes: 3
Views: 1750
Reputation: 30715
The code below show how to get the "title" of the grid column the mouse pointer is over.
Actually, what is displayed in the column header of a TDBGrid column is the Caption
property of the column's Title
object, which has other properties too. The code below reads and displays the Caption
property of the Title
.
As you can see from the online help, the TColumn objects which are the columns of the grid also have Field
and FieldName
properties which you can read if required.
procedure TForm1.DBGrid1MouseMove(Sender: TObject; Shift: TShiftState; X, Y:
Integer);
var
Col,
Row : Integer;
begin
Col := DBGrid1.MouseCoord(X, Y).X;
Row := DBGrid1.MouseCoord(X, Y).Y;
Caption := Format('Col: %d, Row:%d', [Col, Row]);
if (Col > 0) and (Col <= DBGrid1.Columns.Count) then
Caption := Caption + DBGrid1.Columns[Col - 1].Title.Caption;
end;
Upvotes: 5
Reputation: 6013
To answer the question, what you need to know here is
1: Which cell the mouse is over (and hence whether it is over a title Cell)
and
2: the field name (title).
Both these are possible, but not sure how you would use this information to make the title name visible.
1: is to trap the OnMouseMove event and use the MouseCoord property.
2: is to use the resultant column value (if the Row value is 0) and the Fields[ACol].FieldName property.
But perhaps a more direct way to achieve what you want is to set dgTitleHotTrack in the options and set a hottrack style (which would probably have to be a custom one).
Upvotes: 1