<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Iterating over Model Rows</title> <link rel="stylesheet" href="style.css" type="text/css"> <meta name="generator" content="DocBook XSL Stylesheets V1.75.1"> <link rel="home" href="index.html" title="Programming with gtkmm"> <link rel="up" href="chapter-treeview.html" title="Chapter 8. The TreeView widget"> <link rel="prev" href="sec-treeview.html" title="The View"> <link rel="next" href="sec-treeview-selection.html" title="The Selection"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr><th colspan="3" align="center">Iterating over Model Rows</th></tr> <tr> <td width="20%" align="left"> <a accesskey="p" href="sec-treeview.html"><img src="icons/prev.png" alt="Prev"></a> </td> <th width="60%" align="center">Chapter 8. The TreeView widget</th> <td width="20%" align="right"> <a accesskey="n" href="sec-treeview-selection.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> </table> <hr> </div> <div class="sect1" title="Iterating over Model Rows"> <div class="titlepage"><div><div><h2 class="title" style="clear: both"> <a name="sec-iterating-over-model-rows"></a>Iterating over Model Rows</h2></div></div></div> <p> <code class="classname">Gtk::TreeModel</code> provides an STL-style container of its children, via the <code class="methodname">children()</code> method. You can use the familiar <code class="methodname">begin()</code> and <code class="methodname">end()</code> methods iterator incrementing, like so: </p> <pre class="programlisting">typedef Gtk::TreeModel::Children type_children; //minimise code length. type_children children = refModel->children(); for(type_children::iterator iter = children.begin(); iter != children.end(); ++iter) { Gtk::TreeModel::Row row = *iter; //Do something with the row - see above for set/get. }</pre> <div class="sect2" title="Row children"> <div class="titlepage"><div><div><h3 class="title"> <a name="treeview-row-children"></a>Row children</h3></div></div></div> <p> When using a <code class="classname">Gtk::TreeStore</code>, the rows can have child rows, which can have their own children in turn. Use <code class="methodname">Gtk::TreeModel::Row::children()</code> to get the STL-style container of child <code class="classname">Row</code>s: </p> <pre class="programlisting">Gtk::TreeModel::Children children = row.children();</pre> <p> </p> </div> </div> <div class="navfooter"> <hr> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"> <a accesskey="p" href="sec-treeview.html"><img src="icons/prev.png" alt="Prev"></a> </td> <td width="20%" align="center"><a accesskey="u" href="chapter-treeview.html"><img src="icons/up.png" alt="Up"></a></td> <td width="40%" align="right"> <a accesskey="n" href="sec-treeview-selection.html"><img src="icons/next.png" alt="Next"></a> </td> </tr> <tr> <td width="40%" align="left" valign="top">The View </td> <td width="20%" align="center"><a accesskey="h" href="index.html"><img src="icons/home.png" alt="Home"></a></td> <td width="40%" align="right" valign="top"> The Selection</td> </tr> </table> </div> </body> </html>