1.Introduction
This tutorial is also available in
Spanish version, thanks to the work of Daniel Valcarce. You can
read the "TreeView para ninos" at this link.
The TreeView is the most useful Widget of the Gtk+ Toolkit; it's the
only way to display a set of data in your application in a logical order.
Almost every application running in Gnome/Gtk use at least one TreeView
object to render data.
Let's start
First of all, create your own application and insert a TreeView widget. If you are running MonoDevelop and you have
selected to create a Glade# Project, you have a reference to the Glade resource file in your Solution Window:

simply double click on the resource "gui.glade" to open Glade and put a treeview widget from the Glade palette:

at the end you should have a main window with a blank treeview inside:

In MonoDevelop there is a template code that automatically link the Glade resource file to the application at
runtime so you can use the GUI Widget; in the Constructor of your main class there should be:
...
Application.Init ();
Glade.XML gxml = new Glade.XML (null, "gui.glade", "window1", null);
gxml.Autoconnect (this);
Application.Run ();
...
where "
window1" is the name of the main Widget as assigned in Glade.
To make a reference to the widget coming from the "gui.glade" resource, you have to declare them in
the following way (no
new operator needed !!):
...
[Widget] Gtk.Window window1;
[Widget] Gtk.TreeView treeview1;
...
If you build and run your solution you will see your window with a blank area inside: it's the TreeView with no data
to display.
If you don't want to use Glade# in your project, simply create a "tutorial.cs" file with the following lines:
...
Gtk.Window window1 = new Gtk.Window ("Laas Tutorial");
Gtk.TreeView treeview1 = new Gtk.TreeView ();
window1.Add (treeview1);
...
That's all folks.
Finally I like to create my GUI using Glade because:
- All the Widgets are direclty available from the Glade's palette
- It's possible to preview the look&feel of the application
- The main properties of each widget are visible
- It's easy to assign an event hadler to each widget
- other
If you are not using MonoDevelop, remember to link the Gtk library at compile time.