GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Nov 26, 2014 11:01 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Listbox sorting question
PostPosted: Tue May 27, 2008 4:29 pm 
Offline
GTK+ Geek

Joined: Sat May 10, 2008 1:52 pm
Posts: 54
Can anyone point me to the right direction?

I have a listbox/treview with 3 columns (Names | Value1 |Value2 )
I want to sort the rows when I click on any of the column headers.
I need the sorting done for all column, not just the one that I click on,
and, the names, value1 and value2 in a row should stay together.
So the value1 and value2 will be next the the same name as before sorting.
(Something like when you clik on a File browser's filename column label,
the size and date entries are also sorted with the names, not messed up.)

How do I do this?
Thanks for the advice.
Peter


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 27, 2008 10:52 pm 
Offline
Familiar Face

Joined: Wed Apr 02, 2008 10:53 pm
Posts: 28
Hi Peter

If you use a treeview, that's easy:

When you create your columns:

Code:
column = gtk_tree_view_column_new_with_attributes ("Column1 name",
                       renderer,
                       "text",
                       COLUMN1_NUM,
                       NULL);


put the next line just afterwards:

Code:
gtk_tree_view_column_set_sort_column_id (column, COLUMN1_NUM);


Finally append your column to the treeview.

Code:
gtk_tree_view_append_column (treeview, column);


And do that for all your column.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 6:36 pm 
Offline
GTK+ Geek

Joined: Sat May 10, 2008 1:52 pm
Posts: 54
Thanks Micah, works like a charm!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2008 1:51 pm 
Offline
GTK+ Geek

Joined: Sat May 10, 2008 1:52 pm
Posts: 54
Micah, this will work fine - when I click on the column header the list gets sorther.

A QUESTION:

How do I do the sorting programmatically (without clicking)?

Thank you for your help
Peter

cofcof wrote:
Hi Peter

If you use a treeview, that's easy:

When you create your columns:

Code:
column = gtk_tree_view_column_new_with_attributes ("Column1 name",
                       renderer,
                       "text",
                       COLUMN1_NUM,
                       NULL);


put the next line just afterwards:

Code:
gtk_tree_view_column_set_sort_column_id (column, COLUMN1_NUM);


Finally append your column to the treeview.

Code:
gtk_tree_view_append_column (treeview, column);


And do that for all your column.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 05, 2008 12:28 am 
Offline
Familiar Face

Joined: Wed Apr 02, 2008 10:53 pm
Posts: 28
Hi Francis

you could try to use this function:

Code:
void                gtk_tree_sortable_set_sort_column_id
                                                        (GtkTreeSortable *sortable,
                                                         gint sort_column_id,
                                                         GtkSortType order);


So once you get your model, you could do:

Code:
gtk_tree_sortable_set_sort_column_id((GtkTreeSortable*)model, 0, GTK_SORT_ASCENDING);


and that should sort your first column of your model in ascending.


Cheers

Cofcof


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group