Hi
i want to avoid horizontal scroll in the tree, from many posts in the form i understand that there is no some sort of "autosize" property
i found this at on few of the posts
at Expand Event :
ultraTree1.Width = ultraTree1.Width + (e.TreeNode.TextWidth/2);
it doesn't make much sense to me , adding the TextWidth/2 of the clicked node, what if his child node has a long name, it will not work. this is some sort of average that may work generically, i dont want to speak for everyone but for me it just does not work well. it either sets the width too much too less.
i was thinking of changing the width of tree control after each expand incase there is" horizontal ScollBar Scrolling availability", meaning something like
while (ultraTree1.HorizontalScrollBar == true) // or ultraTree1.Scrollbars == Scrollbars.Vertical;
{
ultraTree1.Width ++;
ultraTree1.Refresh();
}
however i have not found the appropriate property to look at. also i couldn't find something like ScrollPosition for horizontal. for vertical i read that it can be set using the TopNode property, but i need the horizontal.
can this be done?
Hello,
Taking a quick look at the UltraTree's API, I don't see anything exposed that would help you out in this regard without looping. However, we do have this information available internally and with a little reflection, you can gain access to it.
Try calling the following method in your AfterExpand and AfterCollapse event handlers:
private void AutoSizeTree()
UIElement controlUIElement = this.ultraTree1.UIElement;
controlUIElement.VerifyChildElements();
// if there is a vertical scrollbar, gets its width from the system
int reservedSpace = (controlUIElement.GetDescendant(typeof(ScrollBarUIElement), Orientation.Vertical) != null) ? SystemInformation.VerticalScrollBarWidth : 0;
reservedSpace += 2;
BindingFlags flags = BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.NonPublic;
Type treeType = typeof(UltraTree);
PropertyInfo field = treeType.GetProperty("RightMostNodePosition", flags);
int rightMostNodePosition = (int)field.GetValue(this.ultraTree1, null);
this.ultraTree1.Width = Math.Max(this.minTreeWidth, rightMostNodePosition + reservedSpace);
With this method, there is also a local member called 'minTreeWidth' which is set in the form's constructor to the Width of the UltraTree. This is used to make sure the control never gets smaller than than the initial width.
Hopefully this helps. Let me know if you require any further assistance.
Thanks,
Chris