Please, help-me, show itens selected in tree_view
- From: Ranieri <ranieri_savage yahoo com br>
- To: gtk-list gnome org
- Subject: Please, help-me, show itens selected in tree_view
- Date: Tue, 15 Jun 2004 00:14:52 -0300
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
#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;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]