Fw: GtkTreeView sorting question



Hi!
I wrote to app-devel-list but didn't get answer yet.
May be here you can help me.


Begin forwarded message:

Date: Sun, 16 Feb 2003 03:44:13 +0300
From: "Grigory Batalov" <grisxa mail ru>
To: gtk-app-devel-list gnome org
Subject: GtkTreeView sorting question


Hi!
I wonder why my column in GtkTreeView isn't sorted just after
starting application. Looks like I missed something. When
I click on header it sets sorting order ascending/descending
and then sorts rows. But not before.

I apply here test program. After starting rows are in order:
Z
C
B
D
A

But sort order is set to ascending and this sorting happens when
I click on header once:
A
B
C
D
Z

-- 
 Grigory Batalov.
#include <stdlib.h>
#include <gtk/gtk.h>

void set_data(GtkTreeStore *treestore)
{
  GtkTreeIter iter;

  gtk_tree_store_append(treestore,&iter,NULL);
  gtk_tree_store_set(treestore,&iter,0,"Z",-1);
  gtk_tree_store_append(treestore,&iter,NULL);
  gtk_tree_store_set(treestore,&iter,0,"C",-1);
  gtk_tree_store_append(treestore,&iter,NULL);
  gtk_tree_store_set(treestore,&iter,0,"B",-1);
  gtk_tree_store_append(treestore,&iter,NULL);
  gtk_tree_store_set(treestore,&iter,0,"D",-1);
  gtk_tree_store_append(treestore,&iter,NULL);
  gtk_tree_store_set(treestore,&iter,0,"A",-1);
}

GtkWidget *create_tree(GtkTreeStore **treestore, GtkCellRenderer *renderer)
{
  GtkWidget *treeview, *win;
  GtkTreeViewColumn *col1;
  
  *treestore=gtk_tree_store_new(2,G_TYPE_STRING,G_TYPE_STRING);
  col1=gtk_tree_view_column_new_with_attributes("Tree",renderer,
						"text",0,NULL);
  treeview=gtk_tree_view_new_with_model(GTK_TREE_MODEL(*treestore));
  gtk_tree_view_append_column(GTK_TREE_VIEW(treeview),col1);
  gtk_tree_view_column_set_sort_column_id(col1,0);
  gtk_tree_view_column_set_sort_order(col1,GTK_SORT_ASCENDING);
  gtk_tree_view_column_set_sort_indicator(col1,TRUE);
  win=gtk_scrolled_window_new(NULL,NULL);
  gtk_container_add(GTK_CONTAINER(win),treeview);
  return win;
}

int main(int argc, char *argv[])
{
  GtkWidget *win, *tree;
  GtkTreeStore *store;
  GtkCellRenderer *renderer;
  
  gtk_init(&argc,&argv);

  win=gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size(GTK_WINDOW(win),300,200);
  g_signal_connect(G_OBJECT(win),"delete_event",G_CALLBACK(gtk_main_quit),NULL);

  renderer=gtk_cell_renderer_text_new();
  gtk_container_add(GTK_CONTAINER(win),(tree=create_tree(&store,renderer)));

  set_data(store);

  gtk_widget_show_all(win);
  gtk_main();
  return 0;
}
CC=gcc
CPPFLAGS=-DG_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED
CFLAGS=`pkg-config --cflags gtk+-2.0` -Wall -ansi -pedantic
LDFLAGS=`pkg-config --libs gtk+-2.0`

.PHONY: all clean

all: test

clean:
	rm -f test *.o

test: test.o

test.o: test.c


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