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

6 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. 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?
  4. 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.
  5. Alessio Bulleri
    Alessio Bulleri avatar
    24 posts
    Member since:
    Sep 2008

    Posted 03 Feb Link to this post

    Hi all,

    I have a grid I've build using HTMLViewDefinition in which some cells have a ColSpan greater than 1.

    I've tried to use this code to show a toolTip for the cells whose values is being truncated, but it works only for the cells that have colSpan == 1.

    How can I take into account the ColSpan value when comparing the text width with the cell width ?

    Thanks a lot

     

  6. Dess
    Admin
    Dess avatar
    1741 posts

    Posted 06 Feb Link to this post

    Hello Alessio,

    Thank you for writing.  

    The provided code snippet for calculating the cell's width uses the ColumnInfo.Width property. However, when using HtmlViewDefinition the column's width must be taken from the RowLayout. That is why if the cell's ColSpan property is greater than 1, the calculation won't be correct in the previously suggested code snippet. Please refer to the following modified 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;
            if (dataCell.MasterTemplate.ViewDefinition is HtmlViewDefinition)
            {
                cellWidth = ((HtmlViewRowLayout)dataCell.TableElement.ViewElement.RowLayout).GetArrangeInfo(dataCell.ColumnInfo).Bounds.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;
        }
    }

    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top