Gtk.TreeSelection Class
The selection object for Gtk.TreeView.

See Also: TreeSelection Members

Syntax

public class TreeSelection : GLib.Object

Remarks

TreeSelection provides a single class for managing selection information on the List/Tree widget.

A TreeSelection object is automatically created when a new Gtk.TreeView widget is created and is inherently tied to it. A TreeSelection cannot exist independently of a Gtk.TreeView. Selection information is retrieved from the Gtk.TreeView with the TreeView.Selection property.

TreeSelection can check the selection status of the tree, as well as select and deselect individual rows. Selection is done completely on the view. As a result, multiple views of the same model can have completely different selections. Additionally, you cannot change the selection of a row that is not currently displayed by the view without expanding its parents first.

One of the important things to remember when monitoring the selection of a view is that the TreeSelection.Changed event is mostly a hint. For example, it may only fire once when a range of rows is selected. It may also fire when nothing has happened, such as when TreeSelection.SelectPath(TreePath) is called on a row that is already selected.

Example

C# Example

using System;
using Gtk;
 
class Selection
{
        static void Main ()
        {
                Application.Init ();
                Window win = new Window ("TreeSelection sample");
                win.DeleteEvent += OnWinDelete;
 
                TreeView tv = new TreeView ();
                tv.AppendColumn ("Items", new CellRendererText (), "text", 0);
 
                ListStore store = new ListStore (typeof (string));
                store.AppendValues ("item 1");
                store.AppendValues ("item 2");
                tv.Model = store;
 
                tv.Selection.Changed += OnSelectionChanged;
 
                win.Add (tv);
                win.ShowAll ();
                Application.Run ();
        }
 
        static void OnSelectionChanged (object o, EventArgs args)
        {
                TreeIter iter;
                TreeModel model;
 
                if (((TreeSelection)o).GetSelected (out model, out iter))
                {
                        string val = (string) model.GetValue (iter, 0);
                        Console.WriteLine ("{0} was selected", val);
                }
        }
 
        static void OnWinDelete (object o, DeleteEventArgs args)
        {
                Application.Quit ();
        }
}
	  

Requirements

Namespace: Gtk
Assembly: gtk-sharp (in gtk-sharp.dll)
Assembly Versions: 2.12.0.0