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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Get cell text rectangle width

Thread ID:





90766 Oct 16,2009 07:35 AM UTC Oct 19,2009 02:41 PM UTC ASP.NET Web Forms (Classic) 1
Tags: GridGroupingControl
Magdalena Magdalena
Asked On October 16, 2009 07:35 AM UTC

Hi there,

If I have a cell which has a small button embedded on the right, how do I obtain the cell text rectangle width? (the width of the column that can accommodate the text).

Obviously Syncfusion.Windows.Forms.Grid.GridControlBase.GetColWidth(int colIndex) returns the entire column width (which includes the button width as well).

Reason for asking is I need to display a text extender on mouse hover when the text is trimmed (by setting the GridStyleInfo.Trimming).
The only way I know the text has been trimmed is by comparing if (text_length > cell_text_rectangle_width).

Thank you for any help :)

Rajadurai C [Syncfusion]
Replied On October 19, 2009 02:41 PM UTC

Hi Magdalena,

Thanks for your interest in Syncfusion Products.

You can check for the cellmodel and get the button width and subtract it from the width calculated, to achieve the expected result. Here is some code for your reference handled in MouseMove event of gridcontrol to show the tooltip for the partially visible text in cell.

int row1, col1 = -1;
int colWidth;
void gridControl1_MouseMove(object sender, MouseEventArgs e)
int row, col;
if (this.gridControl1.PointToRowCol(new Point(e.X, e.Y), out row, out col) && (col != col1 || row != row1))
col1 = col;
row1 = row;
if (this.toolTip1 != null && this.toolTip1.Active)
this.toolTip1.Active = false;
Graphics g = CreateGraphics();
GridStyleInfo style = this.gridControl1[row, col];
if(style.CellType == "ComboBox")
colWidth = this.gridControl1.ColWidths[col] - style.TextMargins.Left - style.TextMargins.Right - style.CellModel.ButtonBarSize.Width;
colWidth = this.gridControl1.ColWidths[col] - style.TextMargins.Left - style.TextMargins.Right;
if (colWidth < g.MeasureString(style.Text, style.GdipFont).Width)
toolTip1.SetToolTip(this.gridControl1, this.gridControl1[row1, col1].Text);
toolTip1.Active = true;

Here is a sample attached for your reference in which this code has been implemented.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon