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

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 07:32 PM UTC

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); 
		base.OnDraw (g, clientRectangle, rowIndex, colIndex, style);

LS Leon Schwartz July 23, 2004 09:10 AM UTC

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

Live Chat Icon For mobile
Up arrow icon