</answer>
</qandaentry>
+<qandaentry>
+<question><para>
+What's the #GtkTreeView equivalent of gtk_clist_find_row_from_data()?
+</para></question>
+
+<answer>
+<para>
+As there is no separate data column in the #GtkTreeModel, there's no
+built in function to find the iter from data. You can write a custom
+searching function to walk the tree and find the data, or use
+gtk_tree_model_foreach().
+</para>
+</answer>
+</qandaentry>
+
<qandaentry>
<question><para>
How do I put an image and some text in the same column?
{
GtkTreeModel *list_store;
GtkTreeIter iter;
+ gboolean valid;
+ gint row_count = 0;
/* make a new list_store */
list_store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_INT);
populate_model (list_store);
/* Get the first iter in the list */
- if (gtk_tree_model_get_iter_first (model, &iter))
- {
- gint row_count = 0;
+ valid = gtk_tree_model_get_iter_first (model, &iter);
- /* Walk through the list, reading each row */
- do
- {
- gchar *str_data;
- gint int_data;
-
- /* Make sure you terminate calls to gtk_tree_model_get(<!>)
- * with a '-1' value
- */
- gtk_tree_model_get (list_store, &iter,
- STRING_COLUMN, &str_data,
- INT_COLUMN, &int_data,
- -1);
-
- /* Do something with the data */
- g_print ("Row &percent;d: (&percent;s,&percent;d)\n", row_count, str_data, int_data);
- g_free (str_data);
-
- row_count ++;
- }
- while (gtk_tree_model_iter_next (model, &iter));
- }
- else
+ while (valid)
{
- /* As gtk_tree_model_get_iter_first(<!>) returned FALSE, the list is empty */
- g_print ("Model is empty.\n");
+ /* Walk through the list, reading each row */
+ gchar *str_data;
+ gint int_data;
+
+ /* Make sure you terminate calls to gtk_tree_model_get(<!>)
+ * with a '-1' value
+ */
+ gtk_tree_model_get (list_store, &iter,
+ STRING_COLUMN, &str_data,
+ INT_COLUMN, &int_data,
+ -1);
+
+ /* Do something with the data */
+ g_print ("Row &percent;d: (&percent;s,&percent;d)\n", row_count, str_data, int_data);
+ g_free (str_data);
+
+ row_count ++;
+ valid = gtk_tree_model_iter_next (model, &iter))
}
}
</programlisting>