GtkTreeView - Selecting the first row



Hello,

I'm having a problem with the selection on a TreeView widget. I have a simple Treeview with one visible column and want to move the selection up and down with 2 buttons. When my application starts there is no row selected, so clicking on a button I need to set the selection to the first row. I thought I could do that with gtk_tree_model_get_iter_first() and gtk_tree_selection_select_iter(), but this doesn't work. Until I'm not selecting with the mouse pointer a row, I can't set a selection with gtk_tree_selection_select_iter(). Calling gtk_tree_selection_get_selected() tells me that a row is selected, but the TreeView shows nothing.

Could somebody give me a hint what I'm doing wrong?

Thanks,
Hannes


Here my piece of code:

GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW(treeview));
GtkTreeIter iter;

gboolean is_Selection = gtk_tree_selection_get_selected(selection, &model, &iter);

// Move selection up/down
if (menu_item->index==0 || menu_item->index==1) {
  if (is_Selection) {
    GtkTreePath *path = gtk_tree_model_get_path(model, &iter);

    if (menu_item->index==1) // down
      gtk_tree_path_next(path);
    else                     // up
      gtk_tree_path_prev(path);

    gtk_tree_model_get_iter(model, &iter, path);
  }
  else {
    gtk_tree_model_get_iter_first(model, &iter);
  }

  gtk_tree_selection_select_iter(selection, &iter);
}





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