Re: Appending to treestore - how to set selection on new entry?



Op 27-08-18 om 08:24 schreef David C. Rankin:
  When I add a new file (entry) to the treestore/treemodel, how do I adjust
the selection so that the new entry is selected? (or how do I get a treepath
or iter from the new entry to allow me to set the selection?) The treestore
holds the name of the entry in the 1st col and then a pointer to a struct
containing details for that textbuffer (e.g. line, col, full path, filemode,
uid/gid, textview and sourceview lang_id along with comment syntax, etc..)
 (1) when I append the entry to the tree, e.g.

    GtkTreeStore *treestore;
    GtkTreeIter toplevel;

toplevel is the treeiter you use to set the selection.

    ...
    treestore = GTK_TREE_STORE(gtk_tree_view_get_model (
                                GTK_TREE_VIEW(app->treeview)));
    /* (validate omitted) */

    /* appeand name and pointer to inst as entry in treeview */
    gtk_tree_store_append (treestore, &toplevel, NULL);
    gtk_tree_store_set (treestore, &toplevel, COLNAME, name, -1);
    gtk_tree_store_set (treestore, &toplevel, COLINST, inst, -1);

    (here I know the 'inst' which is the pointer stored in column 2)

Next is to get the selection from your view with
gtk_tree_view_get_selection and call gtk_tree_selection_select_iter with
the toplevel iter from earlier. It should now have selected the newly
added row.

~infirit


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]