import System import Gtk from 'gtk-sharp' import GLib from 'glib-sharp' # Data function, don't be scared, i describe this in later comments. (: def cell_data (col as TreeViewColumn, cell as CellRenderer, model as TreeModel, iter as TreeIter): cast (CellRendererText, cell).Text = model.GetValue (iter, 1).ToString () [GLib.ConnectBefore] def editing_started (o, args as EditingStartedArgs): cbox = args.Editable as ComboBox # Usual basic app foo. Application.Init () w = Window ("test") w.DeleteEvent += { Application.Quit () } # Our TreeView tv = TreeView () tv.Selection.Changed += def(): iter = TreeIter.Zero if tv.Selection.GetSelected (iter): print "selected person is ${tv.Model.GetValue (iter, 0)}" # This the overload that uses 'attributes' to provide data to the renderer. # It maps a column number in the store (the 0 part) to a GObject property # on the renderer. So for each row it renders, it sets the 'text' property on # our CellRendererText c to be equal to the value of the 0th column of that row. c = CellRendererText () tv.AppendColumn ("Name", c, 'text', 0) # This overload uses a data function to provide the cell with the data it needs # before it tries to render to the TreeView. combo = CellRendererCombo () combo.Editable = true ages = ListStore (typeof (string)) for x in range (18, 25): ages.AppendValues (x.ToString ()) combo.HasEntry = false combo.Model = ages combo.TextColumn = 0 combo.Edited += def (o, args as EditedArgs): print "Just got ${args.NewText} as the result of editing the age!" combo.EditingStarted += editing_started col = tv.AppendColumn ("Age", combo, cell_data as TreeCellDataFunc) # Define the format of our store, and put in bogus values. store = ListStore (typeof (string), typeof (int)) store.AppendValues ("Pete J", 23) store.AppendValues ("Bruce Lee", 57) # Set the TreeView's TreeModel to be our ListStore. tv.Model = store sw = ScrolledWindow () sw.Add (tv) w.Add (sw) w.ShowAll () # Show's how to select an iter iter = TreeIter.Zero if store.GetIterFirst (iter): tv.Selection.SelectIter (iter) # Do it to it! Application.Run ()