GTK TreeView

Hello ML :-),

i've started to write a small GUI with GTK. A lot of thinks work fine, but I have one problem: I want to have a list - like the email list at the usual mail client. Tutorials told me, that I have to use TreeView.

I created an instance of ListStore and added a row. I see the row, and I'm able to click on the row (the row change the color) but i don't see any text in the cells. Does anyone have an idea how to fix it?

Thanks and bye,
  Patrick

here is my code:

list_store = Gtk::ListStore.new(String, String, String)
iter = list_store.append

iter[0] = "First"
iter[1] = "Second"
iter[2] = "Third"

view = Gtk::TreeView.new(list_store)
renderer = Gtk::CellRendererText.new

column = Gtk::TreeViewColumn.new("Foo", renderer)
column.resizable = true
view.append_column(column)

column = Gtk::TreeViewColumn.new("Bar", renderer)
column.resizable = true
view.append_column(column)

column = Gtk::TreeViewColumn.new("Mix", renderer)
column.resizable = true
view.append_column(column)

vbox.pack_start(view)

view.show_all

I created an instance of ListStore and added a row. I see the row, and
I'm able to click on the row (the row change the color) but i don't see
any text in the cells. Does anyone have an idea how to fix it?

Try to replace these lines :

column = Gtk::TreeViewColumn.new("Foo", renderer)
column = Gtk::TreeViewColumn.new("Bar", renderer)
column = Gtk::TreeViewColumn.new("Mix", renderer)

by these :
column = Gtk::TreeViewColumn.new("Foo", renderer, :text => 0)
column = Gtk::TreeViewColumn.new("Bar", renderer, :text => 1)
column = Gtk::TreeViewColumn.new("Mix", renderer, :text => 2)

This is the easy way to affect the content of a column to the data stored in
the model. The last argument of the TreeViewColumn constructor is a hash of
attributes which define a mapping between the data in the model, and what
will appear in the TreeView (those attributes can be reaffected later with
#add_attribute or #set_attributes)

In your case, you created this model :

iter[0] = "First"
iter[1] = "Second"
iter[2] = "Third"

The attribute {:text => 0} means "I want to map directly the content of
iter[0] to the rendered text of the "Foo" column".

Another way to do this is by using the #set_cell_data_func method, which let
you define the rendering of the cell from the given block (using
CellRenderer#text=, for example)

Hello,

thanks for reply. Your code works fine. I'm also able so sort the columns :-).

Thanks,
  Patrick