Re: Gtk::TreeSelection::get_selected_rows()



> // code snippet starts
> // all this presupposes you've set up your tree view, a list or tree 
> store, and a tree view selection somewhere previously
> std::vector<Gtk::TreeModel::Path> pathlist;
> 
> pathlist = myTreeViewSelection->get_selected_rows();
> 
> // Now, you have a list of paths to the selected rows.  For each entry 
> in the list, you can get an iterator which can be deferenced to a 
> Gtk::TreeView::Row.
> 
> for(gint i = 0; i < pathlist.size(); i++)
> {
>     Gtk::TreeModel::iterator iter = 
> myTreeView->get_model().get_iter(pathlist[i]);
>     Gtk::TreeModel::Row row = *iter;

slightly more efficient, perhaps, to do:

    for (TreeSelection::ListHandle_Path::iterator i = pathlist.begin(); 
         i != pathlist.end(); ++i) {
            Row row = *(model.get_iter (*i));
	    ...
    }






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]