This is a migrated thread and some comments may be shown as answers.

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

5 Answers 118 Views
GridView
This is a migrated thread and some comments may be shown as answers.
MikeB
Top achievements
Rank 1
MikeB asked on 10 Mar 2010, 10:00 PM
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

5 Answers, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 11 Mar 2010, 10:49 AM
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.
0
MikeB
Top achievements
Rank 1
answered on 11 Mar 2010, 04:54 PM
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?
0
Svett
Telerik team
answered on 12 Mar 2010, 10:21 AM
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.
0
Alessio Bulleri
Top achievements
Rank 1
answered on 03 Feb 2017, 10:18 AM

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

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 06 Feb 2017, 11:57 AM
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.
Tags
GridView
Asked by
MikeB
Top achievements
Rank 1
Answers by
Svett
Telerik team
MikeB
Top achievements
Rank 1
Alessio Bulleri
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or