I thought that I implement column title hint into my own DBGrid. It's seems to be simple - I thought.
I added
TitleHints : TStrings
that contains information in this format:
name=value
Where name is (0-99) for non-field-based columns, and fieldname for field based columns. Value is the Hint of the column, crlf is \n.
Everything is ok, OnMouseMove is the the Hint based on position.
But: only the first hint shown, the nexts are not. I think this is because the hint mechanism is activated at mouse arriving into the "Control"... When I leave the Control, and come again, I get another hint - once. No matter I set ShowHint to off.
Because I don't want to create my own HintWIndow if possible, I search for a way to reset the Hint mechanism to the Applicaion believe: this is the first case in this control. 开发者_StackOverflow社区Can I do it any way, like "send message", or call "cancelhint" if this exists, etc.
Do you know about this way?
Thanks for your help, and good day to you!
Regards: dd
You can reactivate the hint in your overridden MouseMove
, e.g.:
type
TDBGrid = class(DBGrids.TDBGrid)
private
FLastHintColumn: Integer;
protected
procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
function GetColumnTitleHint(Col: Integer): string;
procedure MouseMove(Shift: TShiftState; X: Integer; Y: Integer); override;
public
constructor Create(AOwner: TComponent); override;
end;
procedure TDBGrid.CMHintShow(var Message: TCMHintShow);
var
Cell: TGridCoord;
begin
if not Assigned(Message.HintInfo) or not (dgTitles in Options) then
inherited
else
begin
Cell := MouseCoord(Message.HintInfo^.CursorPos.X, Message.HintInfo^.CursorPos.Y);
if Cell.Y = 0 then
begin
FLastHintColumn := Cell.X - 1;
Message.HintInfo^.HintStr := GetColumnTitleHint(FLastHintColumn);
end
else
FLastHintColumn := -1;
end;
end;
function TDBGrid.GetColumnTitleHint(Col: Integer): string;
begin
Result := Columns[Col].Title.Caption + ' hint';
end;
procedure TDBGrid.MouseMove(Shift: TShiftState; X, Y: Integer);
var
Cell: TGridCoord;
begin
inherited MouseMove(Shift, X, Y);
if dgTitles in Options then
begin
Cell := MouseCoord(X, Y);
if Cell.Y = 0 then
begin
if Cell.X - 1 <> FLastHintColumn then
Application.ActivateHint(Mouse.CursorPos);
end
else
Application.CancelHint;
end;
end;
constructor TDBGrid.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FLastHintColumn := -1;
end;
GetColumnTitleHint
is only an example, you should implement it to return the correct value from your TitleHints
property.
Hope this helps.
精彩评论