[ruby-gnome2-doc-cvs] [Hiki] update - tut-treeview-model-remove

Back to archive index

ruby-****@sourc***** ruby-****@sourc*****
2004年 4月 3日 (土) 07:34:44 JST


-------------------------
REMOTE_ADDR = 200.216.151.125
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/en/?tut-treeview-model-remove
-------------------------
- {{link "tut-treeview-model-retrieve", "tut-treeview-model", "tut-treeview", "tut-treeview-view"}}
  = Removing Rows
+ {{link "tut-treeview-model-retrieve", "tut-treeview-model", "tut-treeview", "tut-treeview-view"}}
  
  Rows can easily be removed with Gtk::ListStore#remove and Gtk::TreeStore#remove. The removed row will automatically be removed from the tree view as well.
  
  Removing multiple rows at once can be a bit tricky at times, and requires some thought on how to do this best. For example, it is not possible to traverse a store with Gtk::TreeModel#each, check in the code block whether the given row should be removed and then just remove it by calling one of the stores' remove methods. This may not work, because the model is changed from within the foreach loop, which might suddenly invalidate formerly valid tree iters in the each method, and thus lead to unpredictable results.
  
  Here is an example for an alternative approach when removing multiple rows in one go (here we want to remove all rows from the store that contain persons that have been born after 1980, but it could just as well be all selected rows):
  
    underage = []
    liststore.each do |model,path,iter|
      (iter[2] > 1980) and underage.push(Gtk::TreeRowReference.new(model,path))
    end
  
    underage.each do |rowref|
      (path = rowref.path) and liststore.remove(liststore.get_iter(path))
    end
  
  Gtk::ListStore#clear and Gtk::TreeStore#clear come in handy if you want to remove all rows.
  
  Having learned how to add, manipulate, and retrieve data from a store, the next step is to get that data displayed in a Gtk::TreeView widget.





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