Hi,
What is the best way (if there is any) to show pound signs instead of a number if a cell is not wide enough to display the whole formatted number? This is one of features in MS Excel. In order to do this, we need to be able to do at least the following tasks:
1) get the formatted number
2) get the font
3) get Graphics instance to call MeasureString on the formatted number with the font
4) get the width of the cell and it margins
Thanks,
Shaolin
Hi Mike,
Thanks so much for your response!
I did exactly you said. Actually I never used a CreationFilter for this feature in the first place because I thought using a DrawFilter would be more efficient. The following is the code snippet:
case DrawPhase.BeforeDrawForeground: var cellElement = drawParams.Element as CellUIElement; if (cellElement != null) { string text = cellElement.Cell.Text; if (!string.IsNullOrEmpty(text) && text.Length > 1) { Size size = TextRenderer.MeasureText(text, drawParams.Font); if (size.Width > drawParams.ElementDrawingRectInsideBorders.Width) { text = new string('#', text.Length - 1); if(cellElement.Column.CellDisplayStyle == CellDisplayStyle.FormattedText) drawParams.DrawString(drawParams.ElementDrawingRectInsideBorders, text, false, false); else { var textElement = (TextUIElement)cellElement.GetDescendant(typeof(TextUIElement)); if (textElement != null) textElement.Text = text; } return true; } } } break;
Best Regards,Shaolin
Hi Shaolin,
CellDisplayStyle sacrifices functionality for performance. So in this case, you would lose the ability to change the text on the element.
I think what happens in this case is that the CellUIElement draws the text, so you might be able to acheive what you want using a DrawFilter to draw the text yourself. But this would be much more difficult, since you would also have to measure the text yourself, instead of just letting the UIElement do it.
This method does not work if an UltraGridColumn's CellDisplayStyle is set to CellDisplayStyle.FormattedText. There is no TextUIElement created for a CellUIElement, which would result in a better performance. I could see a tooltip showing when text is not fully visible inside the cell. Could you please give me some suggestions please?
Your help is greatly appreciated!
The way it works is that the more specific appearance takes precedence over the more general appearance. So the appearance on the Cell (cell.Appearance) would apply the BackColor Yellow in your example.
There are appearances at many different levels in the grid, and many of the other Infragistics Winforms controls do the same thing.
The cell appearances can be affected by many different appearances: the cell, the Column, the Row, the Override (which is on the band and the layout). So this allows you to set appearances at a very broad level and also override those appearances for more specific objects within the larger set.
What is the background color for a cell if the background color of its row's Appearance is Red, Yellow of row's CellAppearance and Green of column's Appearance? What UltraGridCell's Appearance and how I can change it?
I am in a process to choose a Grid control for our projects. I might have asked improper questions. Thanks for your patience!