Search code examples
cgtk2

How to get the number of rows of gtk.ListStore


How to get the number of items / rows / length / count of gtk.ListStore in C

Here is my sample code:

  store = gtk_list_store_new (NUM_COLS, G_TYPE_STRING, G_TYPE_UINT);

  /* Append a row and fill in some data */
  gtk_list_store_append (store, &iter);
  gtk_list_store_set (store, &iter,
                      COL_NAME, "Heinz El-Mann",
                      COL_AGE, 51,
                      -1);

  /* .
     .
     .
  */
  /* get the length of gtk_list_store*/

Solution

  • Use gtk_tree_model_iter_n_children to obtain the number of rows in the list store.

    In your case

    number_of_rows = gtk_tree_model_iter_n_children(GTK_TREE_MODEL(store), NULL);