Hi,
I've determined that the UltraTree (with FreeForm ViewStyle) does not have a method for automatically sizing the node height to fit wrapped text if CellWrapText=true. I need the cell text to wrap though, so I'm trying to calculate the height of the wrapped text so I can set PreferredCellSize appropriately to show the entire text. Is there a reliable way to do this? I've tried using TextRenderer.MeasureText() with different combinations of TextFormatFlags and Graphics.MeasureString(), but neither one has given me reliably accurate results. Is there a way to get the number of wrapped lines directly from the cell/column object? If not, what would you recommend I use for measuring the text height?
Thanks,
Cassio
Hello,
Could you please let me know the exactly version of Infragistics that you are using. Also is it possible to post a simple sample that demonstrates your issue. I want to see how many lines of text you need to display in a single node.
I ma waiting for your feedback.
Hi Hristo,
I'm using version 2011.2 for Windows Forms (although we'll be upgrading to 2013 soon, so let me know if that will make any difference). The text that needs to be displayed can range from a single word to several lines. The control is being used in a tooltip-like form whose width is variable, so the width available for the columns are dynamically calculated. I want to be able to fit the columns into the form without horizontal scrolling, so if the text has to wrap I need to increase the height of the node to show all the text (vertical scrolling is ok).
I've attached a sample project to demonstrate. Column3 has a long multi-line sample text that wraps in the cell. You can resize Column 3 and it will try to calculate the right height for the cell. It usually leaves a certain amount of whitespace at the bottom of the text, so the calculated height is too tall. The amount of whitespace changes depending on the width of the column, and sometimes it actually gets it right on.
Thank you for the provided sample. When you measuring the string , you assumes that UnitPoint of the graphic objects is Point, but actually it is Display. This meant that graphic measures in the units of the display device and for monitors it is pixels:
http://msdn.microsoft.com/en-us/library/system.drawing.graphicsunit.aspx
so the easiest way to narrow this amount of whitespaces I suggest you to modify your ResizeNodeHeight like:
UltraTreeNodeColumn col = node.Override.ColumnSet.Columns[2];
// this is just a guess at the TextFormatFlags since I don't know what flags the control uses to render the text - maybe the right combination here would make a difference?
// I've tried several with no success
Graphics g = ultraTree1.CreateGraphics();
//g.MeasureString(, , , StringFormat.GenericDefault
int width = col.LayoutInfo.PreferredCellSize.Width;
Size maxSize = new Size(width, Int32.MaxValue); // I've tried passing 0 here as the height instead of MaxValue, but doesn't seem to make a difference
SizeF textSize = g.MeasureString(node.Cells[col].Text,node.Control.Font,maxSize.Width, StringFormat.GenericDefault);//System.Windows.Forms.TextRenderer.MeasureText(g, node.Cells[col].Text, node.Control.Font, maxSize, flags);
g.PageUnit = GraphicsUnit.Point;
//g.DpiY;
int height = (int)Math.Floor(textSize.Height + 20);//(int)Math.Ceiling(textSize.Height * g.DpiY / 72);
col.LayoutInfo.PreferredCellSize = new Size(width, height);
I hope that this will helps you.
Thanks Hristo,
I don't think using Graphics.MeasureString is the right way to go from what I've read. It uses GDI+ to measure the string, but it's being rendered in GDI and the two don't always give you the same measurements. I tried your code in my sample and in some cases if you resize the column, the bottom half of the last line gets cut off.
I played around with the TextFormatFlags and got it to be somewhat close, but it still leaves a fair amount of whitespace at the bottom most of the time. I'm still interested in finding out the right way to do this, but it's good enough for now and I don't have time at the moment to keep messing with it.
Hello,
I am just checking about the progress of this issue. Let me know If you need my further assistance on this issue?
Thank you for using Infragistics Components.
Thank you for your feedback.
Please let me know if you need my further assistance on this matter.
My tree has multiiple node levels, each with its own column set. I'm not sure how I would accomplish that with the UltraGrid. At this point, I have it working well enough to move on and it would require too much effort to try to switch to an UltraGrid.
Thanks for your suggestions and help though.
Maybe you could use UltraGrid instead of UltraTree, and to add additional column “Node” and to group your grid by this column.
I still have the problem that I cannot accurately calculate the height of the cell. The "Auto resize row height" feature will get rid of the problem if it ever makes it into the product, but I still should be able to do this. If I knew exactly how the text is being rendered in the cell, I could use the same flags to measure the text.