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

cells truncating number instead of showing indication cell too short

I was wondering if there is a grid property to set so that when the column width is too small to display the entire number in the grid cell, it shows some indication instead of just truncating the number. Excel handles it by displaying ######.

3 Replies

AD Administrator Syncfusion Team August 1, 2003 11:00 AM

There is no property to handle this. You would have to use events to do this. One event would be QueryCellFormattedText. You could also do it in PrepareViewStyleInfo.


LA Lou Ann Sinicrope August 2, 2003 01:12 PM

How would I go about handling this event to get the result I'm looking for?


AD Administrator Syncfusion Team August 2, 2003 03:40 PM

Since you have to use Graphics.MeasureString to compute the reqired width, it makes more sense to use DrawCell to handle this work since the Graphics object is already available in it. If you use PrepareViewStyleInfo, then you would have to call CreateGraphics to get a Graphics object. In DrawCell, you can test the text to be drawn and if it will not fit, replace it with asterisks. here is a snippest that does this in column 2.
private void gridDataBoundGrid1_DrawCell(object sender, GridDrawCellEventArgs e)
{
	if(e.ColIndex == 2 && e.RowIndex > 0)
	{
		SizeF sz = e.Graphics.MeasureString(e.Style.Text, e.Style.GdipFont);
		if(sz.Width > e.Bounds.Width - e.Style.TextMargins.Left - e.Style.TextMargins.Right)
		{
			e.Style.Text = new string('*', e.Style.Text.Length);
		}
	}
}

Loader.
Live Chat Icon For mobile
Up arrow icon