TreeStore


Object Hierarchy:

Gtk.TreeStore Gtk.TreeStore Gtk.TreeStore GLib.Object GLib.Object GLib.Object->Gtk.TreeStore Gtk.Buildable Gtk.Buildable Gtk.Buildable->Gtk.TreeStore Gtk.TreeDragDest Gtk.TreeDragDest Gtk.TreeDragDest->Gtk.TreeStore Gtk.TreeDragSource Gtk.TreeDragSource Gtk.TreeDragSource->Gtk.TreeStore Gtk.TreeModel Gtk.TreeModel Gtk.TreeModel->Gtk.TreeStore Gtk.TreeSortable Gtk.TreeSortable Gtk.TreeSortable->Gtk.TreeStore

Description:

[ CCode ( type_id = "gtk_tree_store_get_type ()" ) ]
public class TreeStore : Object, Buildable, TreeDragDest, TreeDragSource, TreeModel, TreeSortable

The TreeStore object is a list model for use with a TreeView widget.

It implements the TreeModel interface, and consequentially, can use all of the methods available there. It also implements the TreeSortable interface so it can be sorted by the view. Finally, it also implements the tree drag and drop interfaces.

GtkTreeStore as GtkBuildable

The GtkTreeStore implementation of the Buildable interface allows to specify the model columns with a `<columns>` element that may contain multiple `<column>` elements, each specifying one model column. The “type” attribute specifies the data type for the column.

An example of a UI Definition fragment for a tree store:

<object class="GtkTreeStore">
<columns>
<column type="gchararray"/>
<column type="gchararray"/>
<column type="gint"/>
</columns>
</object>

Example: TreeStore:

public class Application : Gtk.Window {
public Application () {
this.title = "My Gtk.TreeStore";
this.destroy.connect (Gtk.main_quit);
this.set_default_size (250, 100);

Gtk.TreeView view = new Gtk.TreeView ();
setup_treeview (view);
view.expand_all ();
this.add (view);
}

private void setup_treeview (Gtk.TreeView view) {
Gtk.TreeStore store = new Gtk.TreeStore (2, typeof (string), typeof (string));
view.set_model (store);

view.insert_column_with_attributes (-1, "Product", new Gtk.CellRendererText (), "text", 0, null);
view.insert_column_with_attributes (-1, "Price", new Gtk.CellRendererText (), "text", 1, null);

Gtk.TreeIter root;
Gtk.TreeIter category_iter;
Gtk.TreeIter product_iter;

store.append (out root, null);
store.set (root, 0, "All Products", -1);

store.append (out category_iter, root);
store.set (category_iter, 0, "Books", -1);

store.append (out product_iter, category_iter);
store.set (product_iter, 0, "Moby Dick", 1, "$10.36", -1);
store.append (out product_iter, category_iter);
store.set (product_iter, 0, "Heart of Darkness", 1, "$4.99", -1);
store.append (out product_iter, category_iter);
store.set (product_iter, 0, "Ulysses", 1, "$26.09", -1);
store.append (out product_iter, category_iter);
store.set (product_iter, 0, "Effective Vala", 1, "$38.99", -1);

store.append (out category_iter, root);
store.set (category_iter, 0, "Films", -1);

store.append (out product_iter, category_iter);
store.set (product_iter, 0, "Amores Perrors", 1, "$7.99", -1);
store.append (out product_iter, category_iter);
store.set (product_iter, 0, "Twin Peaks", 1, "$14.99", -1);
store.append (out product_iter, category_iter);
store.set (product_iter, 0, "Vertigo", 1, "$20.49", -1);
}

public static int main (string[] args) {
Gtk.init (ref args);

Application sample = new Application ();
sample.show_all ();
Gtk.main ();
return 0;
}
}

valac --pkg gtk+-3.0 Gtk.TreeStore.vala


Namespace: Gtk
Package: gtk+-3.0

Content:

Creation methods:

Methods:

Inherited Members:

All known members inherited from interface Gtk.TreeDragDest
All known members inherited from interface Gtk.TreeDragSource