How change single cell in treeview like a scal/excel worksheet

Hi,

I want to have a single row cursor in a treeview, I’ve thought I could use a CellLayoutDataFunc to change background color only under cursor. I’ve tried this code but I’ve got segfault and I dont understand why…
Where am I wrong ?
I’ve got this error too : gtk_tree_model_get_path: assertion ‘GTK_IS_TREE_MODEL (tree_model)’ failed

Thanks for advices

public class Application : Gtk.Application {
    Gtk.ListStore store = null;
    Gtk.ApplicationWindow win;
    Gtk.TreeView view;

    public Application () {
        Gtk.TreeIter iter;
        store = new Gtk.ListStore (2, typeof(string), typeof(string));
        
        store.append (out iter);
        store.set (iter, 0, "A", 1, "10");
        store.append (out iter);
        store.set (iter, 0, "B", 1, "30");
        store.append (out iter);
        store.set (iter, 0, "C", 1, "50");
        store.append (out iter);
        store.set (iter, 0, "D", 1, "60");
        
    }

	protected override void activate () {
        win = new Gtk.ApplicationWindow(this);

                win.title = "TestApp";
		win.window_position = Gtk.WindowPosition.CENTER;		
		win.set_default_size (800, 600);

        view = new Gtk.TreeView.with_model (store);

        Gtk.CellRendererText cell = new Gtk.CellRendererText ();
        Gtk.TreeViewColumn col = new Gtk.TreeViewColumn.with_attributes ( "Value", cell, "text", 0);			
        col.set_cell_data_func (cell, (Gtk.CellLayoutDataFunc)render_value);
        view.append_column (col);

        col = new Gtk.TreeViewColumn.with_attributes ( "Text", cell, "text", 1);			
        col.set_cell_data_func (cell, (Gtk.CellLayoutDataFunc)render_value);
        view.append_column (col);

        win.add(view);
        win.show_all();
    }

    public void render_value (Gtk.TreeViewColumn column, Gtk.CellRendererText
        cell, Gtk.TreeModel model, Gtk.TreeIter iter) {

            Gtk.TreePath? path = null;
            Gtk.TreeViewColumn? focus_column = null;

            if (model == null) 
                print ("null\n");
            else {
                print ("not null\n");
               // path = store.get_path(iter); //gtk_tree_model_get_path: assertion 'GTK_IS_TREE_MODEL (tree_model)' failed

                path = model.get_path(iter);  // segfault
                print ("segfault ?\n");
            }    
    }

    public static int main (string[] args) {
		Gtk.init (ref args);
         
        Application app = new Application ();
        return app.run();
    }
}

The simple answer is: you don’t. GtkTreeView is not a sheet view, it does not work as the basis for a spreadsheet application, and no attempt at coercing it will make it work that way.

The only known spreadsheet widget written with GTK3 is the Gnumeric sheet widget.

Thanks

OK I understand. but in a TreeView you can display an entire row with the ability to edit a cell. My problem is that when I navigate, the whole row is highlighted when I only want one cell, like picture in attachement.
And finally in my example, why do I have a segfault?
I want this
good
and not this
not_good

Thanks !=

How would anyone know why your example segfaults when you provide no indication of when/where?

Anyway, the best answer to such questions is always to debug it yourself. That can help you figure out your assertion failure too, with e.g. G_DEBUG=fatal-criticals gdb ./your-app.

You can’t. GtkTreeView works with rows in a list/tree layout. There’s no cell-addressing mechanism.

thanks, well I’ll try another solution :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.