9.2. Column Expander Visibility

9.2.1. Hiding the Column Expander

Is it possible to hide the column expander completely? Yes and no. What follows, is probably a dirty hack at best and there is no guarantee that it will work with upcoming Gtk+ versions or even with all past versions (although the latter is easy enough to test of course).

What you can do to hide the column expander is to create an empty tree view column (containing empty strings, for example) and make this the first column in the tree view. Then you can hide that column with gtk_tree_view_column_set_visible. You will notice that the expander column will now automatically move to the formerly second, now first, visible column in the tree view. However, if you call gtk_tree_view_set_expander_column right after the call to _set_visible, then the expander will move back to the hidden column, and no expander is visible any longer.

This means of course that you will have to take care of expanding and collapsing rows yourself and use the appropriate tree view functions. While it is at last thinkable that one could implement custom expanders using custom cell rendereres or pixbuf cell renderers, this is probably a task that will keep you busy for more than five minutes. Keep those head ache tablets nearby if you attempt it anyway...

9.2.2. Forcing Column Expander Visibility

There are situations where an expander should be visible even if the row in question does not have any children yet, for instance when part of a model should only be loaded on request when a node gets expanded (e.g. to show the contents of a directory). This is not possible. An expander is only shown if a node has children.

A work-around for this problem exists however: simply attach an empty child row and set the node to collapsed state. Then listen for the tree view's "row-expanded" signal, and fill the contents of the already existing row with the first new row, then append new child rows. See this mailing list thread for more details.