Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Show custom hint for individual cells in a grid


This question is answered.


Permlink Replies: 2 - Last Post: May 31, 2017 6:16 AM Last Post By: Martin Nijhoff
Martin Nijhoff

Posts: 75
Registered: 8/26/10
Show custom hint for individual cells in a grid  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2017 8:00 AM
Hi,

I'm using C++Builder XE6.

I have a VCL form with a TStringGrid that shows a hint (ShowHint = true).
By default, all controls (including TStringGrid) show a hint when the mouse pointer enters the client area and hide it when the mouse pointer leaves the client area or after a set delay.

I want to show a different hint for each cell in the grid.
To do this, I assigned an OnShowHint event handler in the form's constructor:

__fastcall TForm1::TForm1 (TComponent *Owner) : TForm(Owner)
{
	Application->OnShowHint = DoShowHint;
}


The OnShowHint event handler determines which cell the mouse pointer is on and sets the hint text for that specific cell. It also sets the hint cursor rectangle to the cell's boundaries, so that the hint is hidden when the mouse pointer leaves the cell. This way, each cell has its own hint text and the hint's position changes when the mouse pointer moves to a different cell in the grid.

void __fastcall TForm1::DoShowHint (String &HintStr, bool &CanShow, THintInfo &HintInfo)
{
	if (HintInfo.HintControl == StringGrid1)
	{
		int Col, Row;
 
		StringGrid1->MouseToCell(HintInfo.CursorPos.X, HintInfo.CursorPos.Y, Col, Row);
 
		if (Col >= 0 && Row >= 0)
		{
			HintStr = StringGrid1->Cells[Col][Row];
 
			HintInfo.CursorRect = StringGrid1->CellRect(Col, Row);
		}
	}
}


This works fine for 'normal' hints.

When I assign a custom hint (e.g. TBalloonHint) to the grid, the OnShowHint event handler is never called and the hint is shown for the entire grid instead of a single cell (i.e. the default behaviour). This is because TApplication::ActivateHint() checks if the control's CustomHint property is assigned and skips all the 'normal' hint processing when it is. Apparently, custom hints are shown in TControl::CMMouseEnter() in response to a CM_MOUSEENTER message and hidden in TControl::CMMouseLeave() in response to a CM_MOUSELEAVE message.

How can I show a custom hint (e.g. TBalloonHint) for each cell, so that the behaviour is the same as with 'normal' hints?
Is there a way to set a cursor rectangle for custom hints?

--
Martin
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Show custom hint for individual cells in a grid
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2017 10:49 AM   in response to: Martin Nijhoff in response to: Martin Nijhoff
Martin Nijhoff wrote:

How can I show a custom hint (e.g. TBalloonHint) for each cell, so
that the behaviour is the same as with 'normal' hints?

As you saw, custom hints bypasses all of the VCL's normal hint logic.
So, the only way I can see to accomplish this is to manually track the
mouse movements, such as with the grid's OnMouseMove event, and
whenever the mouse moves to a new cell then you can set the
BalloonHint's Title and/or Description property as needed and then call
its ShowHint() method with new coordinates. For example:

{code}
int LastCol = -1;
int LastRow = -1;

void __fastcall TForm1::StringGrid1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
int Col, Row: Integer;
StringGrid1->MouseToCell(X, Y, Col, Row);

if ((Col != LastCol) || (Row != LastRow))
{
LastCol = Col;
LastRow = Row;

if (BalloonHint1->ShowingHint)
{
TRect R = StringGrid1->CellRect(Col, Row);
R.TopLeft = StringGrid1->ClientToScreen(R.TopLeft);
R.BottomRight = StringGrid1->ClientToScreen(R.BottomRight);
BalloonHint1->Title = ...;
BalloonHint1->Description = ...;
BalloonHint1->ShowHint(R);
}
}
}

Is there a way to set a cursor rectangle for custom hints?

No.

--
Remy Lebeau (TeamB)
Martin Nijhoff

Posts: 75
Registered: 8/26/10
Re: Show custom hint for individual cells in a grid  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2017 6:16 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hi Remy,

I thought so too. Thanks for the confirmation.

--
Martin
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02