diff --git a/doc/ChangeLog b/doc/ChangeLog index bcbb5f5bf..37ea78dc5 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,6 +1,7 @@ 2004-04-27 John Luke * en/Gdk/Threads.xml: document + * en/Gtk/TreeSelection.xml: add example 2004-04-12 Mike Kestner diff --git a/doc/en/Gtk/TreeSelection.xml b/doc/en/Gtk/TreeSelection.xml index f3107243e..a006fef4f 100644 --- a/doc/en/Gtk/TreeSelection.xml +++ b/doc/en/Gtk/TreeSelection.xml @@ -17,6 +17,53 @@ 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 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 is called on a row that is already selected. + + +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 (); + } +} + + GLib.Object