GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Nov 29, 2015 10:34 am

All times are UTC

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: GtkTreeView selection - C
PostPosted: Wed Jan 30, 2008 10:05 am 

Joined: Wed Jan 30, 2008 9:45 am
Posts: 2
Hi all...

im developing GTK+ program with C,
the program need a treeview (of type GtkListStore). i have created i search entry (text entry) widget. what i need is when user input a string in the text entry (like searching...), the treeview automatically select the relevant value in the list (treeview) after he/she press a button, how to accomplish this? i don't get any clue in the documentations.

i want to make it clear...

example, this is a treeview containing a list


then when the user inserted a match string in the search entry list for example : cairo

and after by pressing a button first, let say FIND button. the match string in the list should be selected, in this case cairo.

How to select a row in GtkTreeView?

Thanks before, AJHWB.

 Post subject:
PostPosted: Wed Mar 05, 2008 8:42 am 
GTK+ Guru

Joined: Tue Feb 05, 2008 8:39 am
Posts: 130
Try this my function

void lb_setcursel(GtkTreeView *tree_view, gint sel_index)
  GtkTreeIter iter;
  GtkTreeSelection *sel = gtk_tree_view_get_selection(tree_view);
  GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(tree_view)));
  gboolean valid;
  gint i;

  valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
  for(i=0; valid; i++, valid=gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter))
    if (i == sel_index)
      GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
      gtk_tree_selection_select_iter(sel, &iter);
//      g_signal_emit_by_name(G_OBJECT(tree_view), "cursor_changed");
      gtk_tree_view_scroll_to_cell(tree_view, path, NULL, FALSE, 0, 0);

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group