[ruby-gnome2-doc-cvs] [Ruby-GNOME2 Project Website] update - tut-gtk2-treev-addrnhs

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2012年 8月 25日 (土) 04:58:29 JST


-------------------------
REMOTE_ADDR = 70.49.49.99
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-addrnhs
-------------------------
@@ -50,6 +50,61 @@
     * path : The Gtk::TreePath to be selected. 
     * Returns: self
 
+
+
+There are more ways to deal with tree view selections: either you get a list of the currently selected rows whenever you need it by obtaining Gtk::TreeSelection object via: Gtk::TreeView#selected and then traversing it by running Gtk::TreeSelection#selected_each, or you keep track of all select and unselect actions and keep a list of the currently selected rows around for whenever you need them; as a last resort, you can also traverse your list or tree and check each single row for whether it is selected or not (which you need to do if you want all rows that are not selected for example).
+
+=== Obtaining Gtk::TreeSelection object:
+
+Depending on the Gtk::TreeSelection#mode you gain access either to a single or multiple selections
+
+((*Checking a single selection:*))
+
+ selection = treeview.selection
+
+  if iter = selection.selected
+    puts "selected row is #{iter[0]}"
+  else
+    puts "no row selected"
+  end
+
+((*Multiple selections:*))
+
+When Gtk::TreeSelection#mode is set to Gtk::SELECTION_MULTIPLE you can traverse all the selected rows in the Gtk::TreeSelection object by running its Gtk::TreeSelection#selected_each method:
+
+ treeview.selection.selected_each do |model, path, iter|
+   puts "#{iter[0]} is selected"
+ end
+
+
+((*Example traversing entire TreeView structure:*))
+
+ def traverse_list_to_print_all_rows(store)
+   # get first row in list store
+   return unless iter = store.iter_first
+ 
+   begin
+     puts "Product: #{iter[2]} Buy:#{iter[0]}"
+   end while iter.next!
+ end
+
+((*Example obtaining only NON-selected rows:*))
+
+ def print_only_unselected_rows(store, treeview)
+   # get first row in list store
+   return unless iter = store.iter_first
+
+   all_selections = treeview.selection   # <--- obtain all selections from TreeView
+   begin
+     puts "Product: #{iter[2]} Buy:#{iter[0]}"  if ! all_selections.iter_is_selected?(iter)
+   end while iter.next!                         #  =-==============-=======================
+ end
+
+
+
+
+{{br}}
+
 == Adding New Rows
 
 




ruby-gnome2-cvs メーリングリストの案内
Back to archive index