I have an UltraTree in FreeForm style.
I have hundreds of nodes in the tree, and I have the UltraTree in a split container, so when I resize the split container I want to AutoSize all the nodes in the tree.
I wrote a recursive routine which resizes all columns in all nodes in the Ultra Tree , and it is very slow.
Calling BeginUpdate and EndUpdate on the tree does not help.
I call it as AutoSizeTreeViewNodeColumns(null) and it recursively calls itself on all the children.
Calling PerformAutoSize(AutoSizeMode.VisibleNodes) does not help much and it doesn't work correctly if I call this routine in BeforeExpand, which is another place I call my recursive routine.
PolicyManagerTreeNode inherits from UltraTreeNode, but I don't have any special resize code in it.
Any help would be greatly appreciated. Thanks
private void AutoSizeTreeViewNodeColumns(PolicyManagerTreeNode node) { if (node == null) { LeftTreeView.BeginUpdate(); //LeftTreeView.Visible = false; } if (node == null) { foreach (PolicyManagerTreeNode pnode in LeftTreeView.Nodes) { if (pnode.Override.ColumnSet != null) { foreach (UltraTreeNodeColumn column in pnode.Override.ColumnSet.Columns) { //column.PerformAutoResize(); column.PerformAutoResize(ColumnAutoSizeMode.AllNodes); } } AutoSizeTreeViewNodeColumns(pnode); } } else { if (node.Override.ColumnSet != null) { foreach (UltraTreeNodeColumn column in node.Override.ColumnSet.Columns) { //column.PerformAutoResize(ColumnAutoSizeMode.VisibleNodes); column.PerformAutoResize(ColumnAutoSizeMode.AllNodes); } } foreach (PolicyManagerTreeNode pnode in node.Nodes) { AutoSizeTreeViewNodeColumns(pnode); } } if (node == null) { LeftTreeView.EndUpdate(); //LeftTreeView.Visible = true; } }
I think the problem is that you assigned a column set to each node's override, which usually is not necessary, and certainly shouldn't be done when you have a large number of nodes. A ColumnSet is analagous to a band (i.e., you typically have 2 or 3 of them, not hundreds or thousands). For applications where you are presenting homogeneous data, you should assign the ColumnSet to the Override exposed by the control, NodeLevelOverrides, or a Nodes collection.
I changed my code as I understood your suggestion, and that caused only the nodes I call
PerformAutoSize on to get resized, the other nodes did not get resized. Can you please tell me what I am doing wrong. Thank you.
if (node == null) { LeftTreeView.BeginUpdate(); //LeftTreeView.Visible = false; } if (_disableAutoSize) { return; } if (node == null) { foreach (PolicyManagerTreeNode pnode in LeftTreeView.Nodes) { if (pnode.Override.ColumnSet != null) { foreach (UltraTreeNodeColumn column in pnode.Override.ColumnSet.Columns) { //column.PerformAutoResize(); column.PerformAutoResize(ColumnAutoSizeMode.AllNodes); } } AutoSizeTreeViewNodeColumns(pnode); break; } } else { if (node.Override.ColumnSet != null) { foreach (UltraTreeNodeColumn column in node.Override.ColumnSet.Columns) { //column.PerformAutoResize(ColumnAutoSizeMode.VisibleNodes); column.PerformAutoResize(ColumnAutoSizeMode.AllNodes); //break; } } foreach (PolicyManagerTreeNode pnode in node.Nodes) { AutoSizeTreeViewNodeColumns(pnode); break; } } if (node == null) { LeftTreeView.EndUpdate(); //LeftTreeView.Visible = true; } }
At a glance it looks like you are calling PerformAutoResize on every column multiplied by the total number of nodes. This is not necessary, you only need to call it once, and it will resize for each of the nodes (depending on the ColumnAutoSizeMode).