Let's repeat: 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:
view = Gtk::TreeView.new
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 Gtk::TreeView#model=, which will by itself do very little. However, it is a prerequisite for what we do in the following sections. Alternately you can pass the model as a parameter when you call Gtk::TreeView.new.
# Create empty data store treestore = Gtk::TreeStore.new(String, Integer) # Create a view view = Gtk::TreeView.new # Associate model with view utilizing Gtk::TreeView#model= view.model = treestore
The above can be done with less typing:
# Create empty data store treestore = Gtk::TreeStore.new(String, Integer) # Create view and associate model with it. view = Gtk::TreeView.new(treestore)
Gtk::TreeView#model will return the model that is currently attached to a given tree view, which is 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?).