Chapter 4. Creating a Tree View

In order to display data in a tree view widget, we need to create one first, and we need to instruct it where to get the data to display from.

A new tree view is created with:


  let view = GTree.view () in
  ...

4.1. Connecting Tree View and Model

Before we proceed to the next section where we display data on the screen, we need connect our data store to the tree view, so it knows where to get the data to display from. This is achieved with GTree.view#set_model (gtk_tree_view_set_model), which will by itself do very little. However, it is a prerequisite for what we do in the following sections. GTree.view with ~model option (gtk_tree_view_new_with_model) is a convenience function for the previous two.

GTree.view#model (gtk_tree_view_get_model) will return the model that is currently attached to a given tree view, which is particularly useful in callbacks where you only get passed the tree view widget (after all, we do not want to go down the road of global variables, which will inevitably lead to the Dark Side, do we?).