Re: Please, help-me, show itens selected in tree_view



Le mar 15/06/2004 à 05:14, Ranieri a écrit :
> How to show to which item this chosen team in tree_view?  
> The part of the source code that is wrong is commented.  
> 
> Very Obliged

GtkTreeModel *model2 = GTK_TREE_MODEL (model);
CList *l = gtk_tree_selection_get_selected_rows (tree_view);
GtkTreePath *path;
GtkTreeIter iter;
char *str;

while (l) {
	path = GTK_TREE_PATH (l->data);
	gtk_tree_model_get_iter (model2, &iter, path);
	gtk_model_get (model, &iter, 0, &str, -1);
	g_print (str);
	g_free (str);
	l = l->next;
}
g_list_foreach (l, gtk_tree_path_free, NULL);
g_list_free (l);


> #include <stdio.h>
> #include <gtk/gtk.h>
> 
> int main(int argc, char **argv)
> {
>     int i;
>    
>     GtkWidget *main_window;
>     GtkWidget *fixed_mw;   
>     GtkWidget *tree_view;
>     GtkWidget *scrolled_window;
>     GtkListStore *model;
>     GtkTreeIter iter;
>     GtkCellRenderer *cell;
>     GtkTreeViewColumn *column;
> 
>     gtk_init(&argc, &argv);
> 
>     main_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
>     gtk_window_set_title(GTK_WINDOW(main_window), "MyTitleMyTitleMyTitle");
>     gtk_widget_set_usize(main_window, 650, 350);
>     g_signal_connect(G_OBJECT(main_window), "destroy", 
> G_CALLBACK(gtk_main_quit), NULL);
> 
>     fixed_mw = gtk_fixed_new();
>     gtk_container_add(GTK_CONTAINER(main_window), fixed_mw);
> 
>     model = gtk_list_store_new(1, G_TYPE_STRING);
>     
>     tree_view = gtk_tree_view_new();
>     gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view), 
> GTK_TREE_MODEL(model));
> 
>     scrolled_window = gtk_scrolled_window_new(NULL, NULL);    
>     gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), 
> GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
>     gtk_fixed_put(GTK_FIXED(fixed_mw), scrolled_window, 5, 50);
>     gtk_widget_set_usize(scrolled_window, 640, 300);
>    
>     
> gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), 
> GTK_WIDGET(tree_view));
>   
>     GtkTreeSelection *selection = gtk_tree_view_get_selection 
> (GTK_TREE_VIEW(tree_view));
>     gtk_tree_selection_set_mode (GTK_TREE_SELECTION(selection), 
> GTK_SELECTION_MULTIPLE);
>     
>     for (i=0;i<20;i++)
>     {
>         gchar *msg = g_strdup_printf ("Item%d", i+1);
>         gtk_list_store_append(GTK_LIST_STORE(model), &iter);
>         gtk_list_store_set (GTK_LIST_STORE(model), &iter, 0, msg, -1);
>         g_free(msg);
>     }
>     
>     cell = gtk_cell_renderer_text_new();
>     column = gtk_tree_view_column_new_with_attributes("Itens", cell, 
> "text", 0, NULL);
>     gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), 
> GTK_TREE_VIEW_COLUMN(column));
> 
>     /* The error is here - Start*/
>     gtk_tree_selection_select_all(selection);
>     GtkTreeModel *model2;
>     GList *l = gtk_tree_selection_get_selected_rows(selection, &model2);
>     g_list_first(l);
>     g_print("%s\n", l->data);
>     /* The error is here - End*/
> 
>     gtk_widget_show(scrolled_window);
>     gtk_widget_show(tree_view);
>     gtk_widget_show(fixed_mw);
>     gtk_widget_show(main_window);
>     
>     gtk_main();
>     
>     return 0;
> }
> _______________________________________________
> gtk-list mailing list
> gtk-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-list
> 

Attachment: signature.asc
Description: Ceci est une partie de message =?ISO-8859-1?Q?num=E9riquement?= =?ISO-8859-1?Q?_sign=E9e?=



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