Is there a way to determine if a Cell Value is being trimmed

4 posts, 0 answers
  1. MikeB
    MikeB avatar
    42 posts
    Member since:
    May 2008

    Posted 10 Mar 2010 Link to this post

    Hi,

    I would like to display a ToolTip for a GridView Cell only if the value of the cell is too large to fit within the column width?  The ToolTip would be the complete cell value.  Normally, the value shows an ellipse when it is trimmed but I can not find a property to indicate this.

    Thanks,
    Mike
  2. Svett
    Admin
    Svett avatar
    728 posts

    Posted 11 Mar 2010 Link to this post

    Hi MikeB,

    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 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;
     
            if (size.Width > dataCell.ColumnInfo.Width || dataCell.RowElement.Size.Height < sizeInCell.Height)
            {
                toolTipText = dataCell.Text;
            }
     
            dataCell.ToolTipText = toolTipText;
        }
    }

    If you have further questions, feel free to write us back.

    Sincerely yours,
    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. UI for WinForms is Visual Studio 2017 Ready
  4. MikeB
    MikeB avatar
    42 posts
    Member since:
    May 2008

    Posted 11 Mar 2010 Link to this post

    Svett,

    Thanks for your quick reply and solution.  I tried it and it does work except when only one character is being "trimmed".  In that case, the text width is only .85434 smaller than the cell width.  It seems that, in this case, it should just go ahead and display the character instead of the ellipse.

    At first, I thought it was because I am adding padding to the cells, and you do need to take that into consideration in your solution, but I removed all padding and still had the same results.

    We are using Microsoft San Serif, 8.25pt for the grid font.

    Perhaps, I need to add a fraction to the "Text" width?
  5. Svett
    Admin
    Svett avatar
    728 posts

    Posted 12 Mar 2010 Link to this post

    Hi Michael,

    Thank you for the clarification. The dimensions of a cell include their border width which is not included when the text is measured. So you need to calculate the real dimensions of a cell before subtracting the BorderWidth twice from the height and the width. You can use the following modficated version of my previous code snippet:

    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;
        }
    }

    If you need additional assistance, please do not hesitate to write us back.

    All the best,
    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.
Back to Top