ruby-****@sourc*****
ruby-****@sourc*****
2012年 10月 1日 (月) 06:37:55 JST
------------------------- REMOTE_ADDR = 184.145.80.187 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-treev-rr ------------------------- @@ -189,7 +189,7 @@ === TreeRowReference to the rescue: -Before continuing let us underline that removing a row from a tree model, also removes it from the associated tree vieews. However we here have a much bigger fish to fry: while traversing a store with a Gtk::TreeModel#each loop, it can be dangerous to add or remove rows from the store. Though, we have not yet been talking about removing rows from tree model and view, we should mention here that if you remove a parent row that has a hierarchy of children, it too will be removed, i.e. removing a parent that has children, and grand children, all these descendants will also be removed. It is easy to to remove rows with either Gtk::ListStore#remove or Gtk::TreeStore#remove. The removed row and all its children and any children of children, and so on ..., will also be removed from the tree view as well. +Before continuing let us underline that removing a row from a tree model, also removes it from the associated tree vieews. However we here have a much bigger fish to fry: while traversing a store with a Gtk::TreeModel#each loop, it can be dangerous to add or remove rows from the store. Though, we have not yet been talking about removing rows from tree model and view, we should mention here that if you remove a parent row that has a hierarchy of children, it too will be removed, i.e. removing a parent that has children, and grand children, all these descendants, as well as any of their descendants will also be removed. It is easy to to remove rows with either Gtk::ListStore#remove or Gtk::TreeStore#remove. The removed row and all its children and any children of children, and so on ..., will also be removed from the tree view as well. As stated, removing rows in a loop can be a problem, however. Following is an example showing, how to avoid such a problem, namely, it is not possible to traverse a store with Gtk::TreeModel#each, to check whether the given row should be removed and then simply remove it by calling one of the models' remove methods. This will not work, because when the model is changed from within a 'foreach loop', this invalidates 'tree iters' in the each method, and causes unpredictable behaviour.