Tooltip and AutoEllipsis

7 posts, 1 answers
  1. Jeroen Eikmans
    Jeroen Eikmans avatar
    50 posts
    Member since:
    May 2009

    Posted 10 Sep 2010 Link to this post

    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
  2. Answer
    Svett
    Admin
    Svett avatar
    728 posts

    Posted 15 Sep 2010 Link to this post

    Hi Roel Martens,

    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
  3. Jeroen Eikmans
    Jeroen Eikmans avatar
    50 posts
    Member since:
    May 2009

    Posted 16 Sep 2010 Link to this post

    Hi Svett,

    This works perfectly! Thanks very much.

    Kind regards
  4. Grant
    Grant avatar
    7 posts
    Member since:
    Oct 2009

    Posted 19 May 2011 Link to this post

    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!
  5. Svett
    Admin
    Svett avatar
    728 posts

    Posted 25 May 2011 Link to this post

    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:

    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
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  6. Lily
    Lily avatar
    26 posts
    Member since:
    Feb 2019

    Posted 17 Apr in reply to Svett Link to this post

    With this way, can you change the size of the font?
  7. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3954 posts

    Posted 22 Apr Link to this post

    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.

    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.
Back to Top