{"record":{"id":"5d945a8327a99452","repo":"Unity-Technologies/UnityCsReference","slug":"setting-columnindexfortreefoldouts-can-only-be-set","errorCode":null,"errorMessage":"Setting columnIndexForTreeFoldouts can only be set when using TreeView with a MultiColumnHeader","messagePattern":"Setting columnIndexForTreeFoldouts can only be set when using TreeView with a MultiColumnHeader","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControl.cs","lineNumber":196,"sourceCode":"        protected float extraSpaceBeforeIconAndLabel\n        {\n            get { return m_GUI.extraSpaceBeforeIconAndLabel; }\n            set { m_GUI.extraSpaceBeforeIconAndLabel = value; }\n        }\n\n        protected float customFoldoutYOffset\n        {\n            get { return m_GUI.customFoldoutYOffset; }\n            set { m_GUI.customFoldoutYOffset = value; }\n        }\n\n        protected int columnIndexForTreeFoldouts\n        {\n            get { return m_GUI.columnIndexForTreeFoldouts; }\n            set\n            {\n                if (multiColumnHeader == null)\n                    throw new InvalidOperationException(\"Setting columnIndexForTreeFoldouts can only be set when using TreeView with a MultiColumnHeader\");\n\n                if (value < 0 || value >= multiColumnHeader.state.columns.Length)\n                    throw new ArgumentOutOfRangeException(\"value\", string.Format(\"Invalid index for columnIndexForTreeFoldouts: {0}. Number of available columns: {1}\", value, multiColumnHeader.state.columns.Length));\n\n                m_GUI.columnIndexForTreeFoldouts = value;\n            }\n        }\n\n        protected bool useScrollView\n        {\n            get { return m_TreeView.useScrollView; }\n            set { m_TreeView.useScrollView = value; }\n        }\n\n        protected Rect GetCellRectForTreeFoldouts(Rect rowRect)\n        {\n            if (multiColumnHeader == null)\n                throw new InvalidOperationException(\"GetCellRect can only be called when 'multiColumnHeader' has been set\");","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/GUI/TreeView/TreeViewControl/TreeViewControl.cs#L178-L214","documentation":"Thrown by the setter of columnIndexForTreeFoldouts when multiColumnHeader is null. The foldout (expand/collapse arrow) column index is only meaningful when the TreeView uses a MultiColumnHeader; without one there are no columns to index into.","triggerScenarios":"Setting columnIndexForTreeFoldouts on a TreeView constructed without a MultiColumnHeader (i.e. the single-column TreeView(TreeViewState) constructor); setting the property before assigning a MultiColumnHeader.","commonSituations":"Copying code from a multi-column TreeView example into a single-column TreeView; refactoring that removes the MultiColumnHeader but leaves the foldout column setting behind.","solutions":["Construct the TreeView with the MultiColumnHeader overload: new TreeView(state, multiColumnHeader).","If you do not need columns, remove the columnIndexForTreeFoldouts assignment entirely.","Ensure multiColumnHeader is assigned before setting columnIndexForTreeFoldouts."],"exampleFix":"// before\nvar tree = new TreeView<int>(state);\ntree.columnIndexForTreeFoldouts = 1; // throws\n\n// after\nvar header = new MultiColumnHeader(headerState);\nvar tree = new TreeView<int>(state, header);\ntree.columnIndexForTreeFoldouts = 1;","handlingStrategy":"type-guard","validationCode":"if (tree.multiColumnHeader != null)\n    tree.columnIndexForTreeFoldouts = desiredIndex;","typeGuard":"static bool HasMultiColumnHeader<T>(TreeView<T> tv) => tv.multiColumnHeader != null;","tryCatchPattern":null,"preventionTips":["Use the TreeView(state, multiColumnHeader) constructor when you need columns.","Guard columnIndexForTreeFoldouts assignments with a multiColumnHeader null check.","Do not copy multi-column settings into single-column TreeViews."],"tags":["unity","treeview","multicolumnheader","configuration","foldout"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}