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

Visible text versus actual text

Hi, I was wondering if there was a way to programmatically tell if the text in a given cell is being truncated (trimmed). I am working on something base on your EllipsisCell example, but I only want to show the ellipsis button if the text in that cell is indeed longer than what can be shown. This is in a data-bound grid, if it matters. TIA.

2 Replies

AD Administrator Syncfusion Team July 22, 2004 03:32 PM

You will have to measure teh string yourself. One place you can try to do this is to add an OnDraw override to the EllipsisCellRenderer class. Here is a try at it. It probably needs tweaking some.
protected override void OnDraw(Graphics g, Rectangle clientRectangle, int rowIndex, int colIndex, GridStyleInfo style)
{
	Rectangle rect = new Rectangle(clientRectangle.X, clientRectangle.Y, clientRectangle.Width + this.Model.ButtonBarSize.Width, clientRectangle.Height);
	int width =  (int) g.MeasureString(style.Text, style.GdipFont).Width;
			
	if(width < rect.Width)
	{
		style.ShowButtons = GridShowButtons.Hide;
		GridStaticCellRenderer.DrawText(g, style.Text, style.GdipFont, clientRectangle, style, style.TextColor, false); 
	}
	else
		base.OnDraw (g, clientRectangle, rowIndex, colIndex, style);
}


LS Leon Schwartz July 23, 2004 05:10 AM

Thanks Clay! Didn''t even need to modify your code!

Loader.
Live Chat Icon For mobile
Up arrow icon