i've set the following property on my grid:
now say i put the following value into it:
case (1) - if the cell is really small, it does the following (which i like):
case (2) - if the cell is a little bigger, it does the following (i don't like this):
if it's big enough to display that elipsis, i'd rather it display another digit of precision after the decimal place. with case (1) i'm ok sacrificing precision to get the ellipsis because otherwise the user has no means of knowing whether that says 872 or 87234591.
but with case (2), the user can see the decimal point so s/he knows the absolute size of the number in there (can't confuse 872 with 8725897)
case (3) - sometimes i get this:
in this case (3) there are four periods because the decimal place is right next to the ellipsis. this is confusing.
what i'd like is these cases to show:
any advice?
Hi,
The TextTrimming is done by the DotNet Framework GDI+ text drawing methods. So we really don't have any control over this, other than passing in an option that says to show an ellipsis if the text doesn't fit.
So the only way you could do something like this would to use a DrawFilter and draw the text yourself. You would have to measure the text to determine what fits and then draw it yourself using GDI+ in code.
that sounds terrifying. how do i determine how much of the text is visible?
mildavi said:that sounds terrifying.
I agree. It's not going to be fun. :)
mildavi said:how do i determine how much of the text is visible?
You would handle the drawing of the TextUIElement using a DrawFilter. The element size is already determined by the grid. So you would use that as your bounding size and then use MeasureString to determine how many charactters can fit. Since you will also need to determine when the ellipsis fits, you will probably need to measure multiple times using trial-and-error to get the right string.
thanks, that was a big help. i decided to use a draw filter to display a little overflow "indicator" triangle in the corner of the cell instead, kind of the way excel displays a warning. this way, the user is notified that there is text overflow, but doesn't sacrifice precision by using the ellipsis.
in the following code, i make my little smaller if it's in the last cell in the row. but that doesn't seem like the right thing to do. i should be messing with the offset instead. something to do with cell / row borders, i imagine. any advice?
}
ack - how do i get it to not reformat my code into one big smush?
YES!
RectInsideBorders was the magic infragistics property I was looking for.
Fanx.
mildavi said:why does the last cell in the row require a larger triangle
You are probably right, it probably has to do with the borders. A cell does not draw all four of it's own borders. It only draws one or two sides and relies on the adjacent cells to draw the others. So the last cell in the row probably has to draw the right border where the other cells to do. You should probably use the element.RectInsideBorders (as opposed to Rect), if you are not already doing so.
mildavi said:is there a better way to detect this than what i'm currently doing
I didn't look at the code that closely, but if it's working, I say go with it. :)
yea, it works fine. i'm just curious why i have to muck around with that triangleSize bit.
Your sample attached here seems to work okay. Are you still having a problem with this?Or did yuo just post this for others to use? :)
using System.Drawing;
using Infragistics.Win;
using Infragistics.Win.UltraWinGrid;
namespace Infragistics.Test
{
class OverflowIndicatorFilter : IUIElementDrawFilter
public DrawPhase GetPhasesToFilter(ref UIElementDrawParams drawParams)
if (drawParams.Element is CellUIElement)
return DrawPhase.BeforeDrawImage;
return DrawPhase.None;
public bool DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams)
switch(drawPhase)
case DrawPhase.BeforeDrawImage:
var cell = drawParams.Element.SelectableItem as UltraGridCell;
if (cell == null) return true;
if (!ShouldDraw(cell, drawParams.Graphics, drawParams.Font)) return true;
DrawTriangle(drawParams.Graphics, drawParams.Element.Rect, IsLastCell(cell));
return true;
default:
return false;
/// <summary>
/// Measure the contents of the cell. If the text is bigger than the cell width, draw the triangle.
/// </summary>
private static bool ShouldDraw (UltraGridCell cell_, Graphics graphics_, Font font_)
var size = graphics_.MeasureString(cell_.Text, font_);
return (size.Width > cell_.Width);
/// Need to check if it's the last cell in the row because it needs one less
/// pixel of triangle. No cell border, just row border?
private static bool IsLastCell (UltraGridCell cell_)
int n = cell_.Row.Cells.Count;
int i = cell_.Row.Cells.IndexOf(cell_);
return n == i + 1;
private static void DrawTriangle (Graphics g_, Rectangle rect_, bool last_)
int triangleSize = last_ ? 7 : 8; // if it's in the last row, need a smaller triangle
var corner = new Point(rect_.Location.X + rect_.Width, rect_.Location.Y + rect_.Height);
var vertical = new Point(corner.X, corner.Y - triangleSize);
var horiz = new Point(corner.X - triangleSize, corner.Y);
g_.FillPolygon(Brushes.Black, new[ { corner, vertical, horiz });