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

アーカイブの一覧に戻る

ruby-****@sourc***** ruby-****@sourc*****
2003年 11月 17日 (月) 06:47:45 JST


-------------------------
REMOTE_ADDR = 64.30.138.196
REMOTE_HOST = 
        URL = http://ruby-gnome2.sourceforge.jp/?tut-treeview-model-remove
-------------------------
= Removing Rows

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 functions. 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 メーリングリストの案内
アーカイブの一覧に戻る