Jeroen Eikmans
Top achievements
Rank 1
Jeroen Eikmans
asked on 10 Sep 2010, 11:45 AM
Hi,
Ik would like to display a tooltip on a cell when the text in the cell has an ellipsis.
The AutoEllipsis nicely adds the Ellipsis when the text is to big for the cell, but instead of having the users change the width of the column i would like a tooltip which shows the entire text.
I couldn't find documentation on how to do this so if someone can point me in the right direction...
Kind regards
Ik would like to display a tooltip on a cell when the text in the cell has an ellipsis.
The AutoEllipsis nicely adds the Ellipsis when the text is to big for the cell, but instead of having the users change the width of the column i would like a tooltip which shows the entire text.
I couldn't find documentation on how to do this so if someone can point me in the right direction...
Kind regards
6 Answers, 1 is accepted
0
Accepted
Hi Roel Martens,
I hope this helps.
Kind regards,
Svett
the Telerik team
You can measure the height and width of the text and then depending on that to compare it with the cell dimensions. If the text exceeds the size of the cell, then you can show your tool tip text for the specified cell. You can easily achieve that behavior on the ToolTipTextNeeded event. You should use TextPart object to measure text height and width.
private
void
radGridView_ToolTipTextNeeded(
object
sender, Telerik.WinControls.ToolTipTextNeededEventArgs e)
{
GridDataCellElement dataCell = sender
as
GridDataCellElement;
if
(dataCell !=
null
)
{
TextPart textPart =
new
TextPart(dataCell);
SizeF size = textPart.Measure(
new
SizeF(
float
.PositiveInfinity,
float
.PositiveInfinity));
SizeF sizeInCell = textPart.Measure(
new
SizeF(dataCell.ColumnInfo.Width,
float
.PositiveInfinity));
string
toolTipText =
null
;
float
cellWidth = dataCell.ColumnInfo.Width - dataCell.BorderWidth * 2;
float
cellHeight = dataCell.Size.Height - dataCell.BorderWidth * 2;
if
(size.Width > cellWidth || cellHeight < sizeInCell.Height)
{
toolTipText = dataCell.Text;
}
dataCell.ToolTipText = toolTipText;
}
}
I hope this helps.
Kind regards,
Svett
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jeroen Eikmans
Top achievements
Rank 1
answered on 16 Sep 2010, 12:09 PM
Hi Svett,
This works perfectly! Thanks very much.
Kind regards
This works perfectly! Thanks very much.
Kind regards
0
Grant
Top achievements
Rank 1
answered on 20 May 2011, 03:22 AM
Hi Svett, I'm using a recent build of the Telerik WinControls (2011.1.11.419) and would like to use this functionality. The ellipses work great; they make the grid look more polished. The tooltip feature sounds very useful, but I'm having trouble implementing it. I pasted your code below exactly as-is (other than adding a single line to enable the tooltip if tooltiptext has a value) and registered the event with my grid. Sometimes when I hover the mouse over a cell in which the text is cut off, I get the correct cell content in the tooltip. I'll hover over a few others and they all work fine. But then suddenly I'll hover over another cell and the tooltip that pops up will contain content from one of the previous cells. I stepped through the code line by line... dataCell is pointing to the correct cell, it's "value" property contains the cell's correct text, and the correct text is assigned to tooltiptext. But then I hit F5 to continue running the app and the tooltip that pops up is the text from another cell completely. Any ideas? Thanks!
0
Hi Grant Winney,
There is a know issue regarding tool tips in Q1 2011 SP1 (2011.1 11.419). We addressed the issue in our latest internal build (2011.1 11.510) which you can download from your account. I recommend that you try it. Also you should use a modified version of my previous code snippet:
If the issue still occurs, I would kindly ask you to open support ticket. There you can enclose a sample project where the issue is presented.
Best wishes,
Svett
the Telerik team
There is a know issue regarding tool tips in Q1 2011 SP1 (2011.1 11.419). We addressed the issue in our latest internal build (2011.1 11.510) which you can download from your account. I recommend that you try it. Also you should use a modified version of my previous code snippet:
private
void
radGridView1_ToolTipTextNeeded(
object
sender, Telerik.WinControls.ToolTipTextNeededEventArgs e)
{
GridDataCellElement dataCell = sender
as
GridDataCellElement;
if
(dataCell !=
null
)
{
TextPart textPart =
new
TextPart(dataCell);
SizeF size = textPart.Measure(
new
SizeF(
float
.PositiveInfinity,
float
.PositiveInfinity));
SizeF sizeInCell = textPart.Measure(
new
SizeF(dataCell.ColumnInfo.Width,
float
.PositiveInfinity));
string
toolTipText =
null
;
float
cellWidth = dataCell.ColumnInfo.Width - dataCell.BorderWidth * 2;
float
cellHeight = dataCell.Size.Height - dataCell.BorderWidth * 2;
if
(size.Width > cellWidth || cellHeight < sizeInCell.Height)
{
toolTipText = dataCell.Text;
}
e.ToolTipText = toolTipText;
}
}
If the issue still occurs, I would kindly ask you to open support ticket. There you can enclose a sample project where the issue is presented.
Best wishes,
Svett
the Telerik team
0
Lily
Top achievements
Rank 1
Veteran
answered on 17 Apr 2020, 02:39 PM
With this way, can you change the size of the font?
0
Hello, Lily,
According to the provided information, I am not sure whether you are asking about the font of the cell itself or the tool tip.
You can change the cells' font by handling the CellFormatting event.
Thus, the TextPart will measure the desired value of the cell considering the font as well.
However, if you want to change the font of the tool tip, you can enable the ToolTip.OwnerDraw property and handle the Draw event of the tool tip where you can draw desired text with the desired font and fill color. Note that the ToolTip is the standard ToolTip and you can customize it as it demonstrated in the following MSDN articles:
https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.tooltip.ownerdraw?redirectedfrom=MSDN&view=netframework-4.8#System_Windows_Forms_ToolTip_OwnerDraw
https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.tooltip.draw?view=netframework-4.8
I hope this information helps.
According to the provided information, I am not sure whether you are asking about the font of the cell itself or the tool tip.
You can change the cells' font by handling the CellFormatting event.
Thus, the TextPart will measure the desired value of the cell considering the font as well.
However, if you want to change the font of the tool tip, you can enable the ToolTip.OwnerDraw property and handle the Draw event of the tool tip where you can draw desired text with the desired font and fill color. Note that the ToolTip is the standard ToolTip and you can customize it as it demonstrated in the following MSDN articles:
https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.tooltip.ownerdraw?redirectedfrom=MSDN&view=netframework-4.8#System_Windows_Forms_ToolTip_OwnerDraw
https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.tooltip.draw?view=netframework-4.8
I hope this information helps.
Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Our thoughts here at Progress are with those affected by the outbreak.