Ideally, I'd like to get my tree to automatically resize its columns based on weights, but that doesn't seem to work in Grid view, so the next best thing would be to do it in code. How can I change the width of a column in code? This ought to be simple, but it's not.
Aaron
Hi,
You could try the following:
foreach (UltraTreeNodeColumn column in ultraTree1.ColumnSettings.RootColumnSet.Columns)
column.PerformAutoResize();
For each column in the columnset call PerformAutoResize Method
Let me know if this works for you.
Regards,
Stefaniya
Thanks, but there's two issues with that: first, won't that affect only one column set? I suppose I could iterate through ColumnSets and do it to each one, but second, what if I don't want to resize the columns to their contents? What I'd actually like is to resize the columns to the width of the tree view control, while controlling the percentage of the width that each one gets. All I need is a SetWidth call, but there doesn't seem to be one.
Thanks, Aaron
Hi Aaron,
The tree lays out the nodes using a GridBagLayout. So there's no Width property on the column.To set the width of a column, you use either the PreferredLabelSize or PreferredCellSize (or both) on the LayoutInfo for the column.
columnSet.Columns[0].LayoutInfo.PreferredLabelSize
That's it, thanks very much. However, there's one complication - how can I tell what the width of the inset is for a given column set? In other words, if I'm using this column set at level 3 of the tree, the left side of the column header is not going to be at the left side of the tree view's area. What's that offset?
You can use:
this.ultraTree1.IndentResolved
For the benefit of anyone else who's trying to do this, the full calculation of how much space is available at indent level N (1-based) is:
availableWidth = treeView.Width - N * treeView.IndentResolved - SystemInformation.VerticalScrollBarWidth