3.4. Manipulating Row Data

Adding empty rows to a data store is not terribly exciting, so let's see how we can add or change data in the store.

GTree.list_store#set (gtk_list_store_set) and GTree.tree_store#set (gtk_tree_store_set) are used to manipulate a given row's data. Both GTree.list_store#set and GTree.tree_store#set take three arguments. The first argument is the iter pointing to the row whose data we want to change. The second argument, the column, refers to the model column which we want to change. The third argument, the data, should be of the same data type as the model column.

Here is an example where we create a store that stores two strings and one integer for each row:


  let cols = new GTree.column_list in
  let col_first_name = cols#add Gobject.Data.string in
  let col_last_name = cols#add Gobject.Data.string in
  let col_year_born = cols#add Gobject.Data.int in
  let liststore = GTree.list_store cols in

  (* Append an empty row to the list store. Iter will point to the new row *)
  let row = liststore#append () in

  (* Fill fields with some data *)
  liststore#set ~row ~column:col_first_name "Joe";
  liststore#set ~row ~column:col_last_name "Average";
  liststore#set ~row ~column:col_year_born 1970;