Re: GtkTreeView - Selecting the first row



Stefan Kost wrote:
hi,

just a wild guess, are use using the GTK_SELECTION_BROWSE selection mode?

GtkTreeSelection *select;

select = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree));
gtk_tree_selection_set_mode (select, GTK_SELECTION_BROWSE);

Yes, I already tried that without success. I've found out, that the problem is the focus of the widget. When my app starts, another widget seems to have the focus and pressing tab or a cursor key moves the focus to the TreeView and the selection works.
So, my new questions is: How can I set the focus on the TreeView?
gtk_widget_grab_focus(treeview) doesn't work.




Hannes Mayr wrote:

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);
}


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list





--
INDUNET GmbH/Srl - Trientstr. 36c - I-39040 Salurn
Tel: +39 0471 883650 - Fax: +39 0471 883648
www.indunet.it - info indunet it - support indunet it

INFORMAZIONI STRETTAMENTE CONFIDENZIALI
Il presente messaggio e relativi
allegati, contengono informazioni strettamente riservate e destinate
esclusivamente al destinatario sopra indicato, il quale è l'unico
autorizzato ad usarli, copiarli e, sotto la propria responsabilità,
diffonderli. Chiunque ricevesse questo messaggio per errore o
comunque lo leggesse senza esserne legittimato è avvertito che - in
base alle disposizioni del D. Lgs 196/2003 - trattenerlo, copiarlo,
divulgarlo, distribuirlo a persone diverse dal destinatario è
severamente proibito ed è pregato di inviarlo immediatamente al
mittente distruggendo l'originale. Indunet Srl è in possesso di
questo indirizzo email ottenuto per comunicazione diretta dell'
interessato a Indunet Srl o a suoi collaboratori oppure da avvisi,
siti internet e altri documenti pubblici. Non siamo in possesso
di altri dati che riguardano l'intestatario dell'email salvo quanto
comunicato dall'interessato, e l'inizio di un rapporto di tipo
commerciale è subordinato all'invio della nostra informativa al
trattamento dei dati personali e all' accettazione da parte dell'
interessato. Tali dati verranno conservati fino a che i servizi e i
prodotti offerti da Indunet Srl non saranno più necessari o graditi.
Grazie.




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