We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Tooltip of the cell text when text is longer than cell width

Hi,
 
I am looking for a way to
 
1) set a tooltip text (something along the lines of e.Style.CellTipText = e.Style.Text) IF the Text inside the cell is longer than the width of that cell.
 
2) the tooltip display time should be customisable.
 
Please let me know how can this be achieved. Thank you
 

6 Replies

GM Gaukhar Massabayeva March 14, 2013 01:50 PM UTC

Oh and the tooltip should be available in nested rows as well.


VK Vinish Kumar K Syncfusion Team March 18, 2013 05:34 PM UTC

Hi Gaukhar Massabayeva,

 

Thank you for your interest in Syncfusion.

 

Sorry for the inconvenience caused with delay we have analyzed your query with the provided details. You can set the tooltip for the cells which contain the large text using the PrepareViewSyleInfo event please refer the following codes for your references.

 

void gridControl1_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e)

        {

            //e.Style.CellTipText = e.Style.Text;

 

            GridCurrentCell cc = this.gridControl1.CurrentCell;

            GridTextBoxCellRenderer rend = this.gridControl1.CurrentCellRenderer as GridTextBoxCellRenderer;

            if (rend != null)

            {

                int textLength = rend.Control.Text.Length * 6;

                if (this.gridControl1.ColWidths[cc.ColIndex] < textLength)

                    e.Style.CellTipText = e.Style.Text;

                else

                    e.Style.CellTipText = "";

            }

        }

 

 

2. To customize the tooltip text display by the AutoPopDelay code. Please refer the following code to delay.

 

this.gridControl1.CellToolTip.AutoPopDelay = 1000;

 

 

Please refer the attached sample file also which contain the above workaround and let me know if you need any more helps regarding this. We will provide better solution for you.

 

Regards,

Vinish



CS_6420a5d8.zip


GM Gaukhar Massabayeva March 19, 2013 04:54 PM UTC

Hi Thank you for getting back to me.
 
I tried the sample you provided. It works great. However, once the is a column detected whose text exceeds the colwidth for some reason tooltip starts to appear for all cell, even if the text length does not exceed colwidth. :S


VK Vinish Kumar K Syncfusion Team March 20, 2013 07:29 AM UTC

Hi Gaukhar,

 

Sorry for the inconvenience caused.

 

Query

show tool tip on a grid grouping control cell, if text length is greater than the width of the column

We have deeply analyzed your query to show tool tip on a if text length is greater than the width of the column. You can use  the TableControl’s MouseMove event and check whether the cell text length is greater than the cell’s column width, if the text length is larger than the column width then show the tooltip with cell's text.

 

This can be achieved by "Active" property of the tooltip object. The following code explains the same.

 

 

Please use the attached sample file also.

 

Sample file : http://www.syncfusion.com/downloads/Support/DirectTrac/105872/GGC_CustomToolTip-838514140.zip

 

 

Please let me know if you have any concerns.

 

Regards,

Vinish



AT Adam Thompson May 12, 2018 12:48 AM UTC

I would like to achieve the same thing except the code help is not showing in this thread. 


SN Sindhu Nagarajan Syncfusion Team May 14, 2018 12:55 PM UTC

Hi Adam, 

Thanks for contacting Syncfusion support. 

To set tooltip text for cells whose cellvalue is longer than the column width of the grid cell, MouseMove event can be used. To check the cell text length is greater than the cell’s column width, GetMeasureString() method can be used. Please refer to the below code and sample, 
 
Code Example 
//Event Triggering          
gridControl1.MouseMove += GridControl1_MouseMove; 
 
//Event Customization   
private void GridControl1_MouseMove(object sender, MouseEventArgs e) 
{ 
    int row, col; 
    Point p = new Point(e.X, e.Y); 
    gridControl1.PointToRowCol(p, out row, out col); 
    GridStyleInfo style = gridControl1[row, col] as GridStyleInfo; 
    if(style!=null) 
    { 
        Graphics g = gridControl1.CreateGraphics(); 
        float a = g.MeasureString(style.CellValue.ToString(), style.GdipFont).Width; 
        if (this.gridControl1.ColWidths[col] < a) 
        { 
            style.CellTipText = style.Text; 
        } 
        else 
            style.CellTipText = ""; 
    } 
} 


Please let us know if you have any other queries. 

Regards, 
Sindhu  


Loader.
Live Chat Icon For mobile
Up arrow icon