Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » GridCtrl and sort at runtime
GridCtrl and sort at runtime [message #8298] Thu, 01 March 2007 14:20 Go to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
Hello,

I've put some data in a GridCtrl and now I would like to sort it. I do not want give to the user the possibility to sort the GridCtrl because I need to do it one time for all.
With the arrayctrl I had the command arrayctrl.Sort(column). Is there something equivalent (ascending/descending) for gridctrl?
A workaround is to sort the data before to insert them.

Luigi
Re: GridCtrl and sort at runtime [message #8299 is a reply to message #8298] Thu, 01 March 2007 15:49 Go to previous messageGo to next message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

forlano wrote on Thu, 01 March 2007 08:20

I've put some data in a GridCtrl and now I would like to sort it. I do not want give to the user the possibility to sort the GridCtrl because I need to do it one time for all.
With the arrayctrl I had the command arrayctrl.Sort(column). Is there something equivalent (ascending/descending) for gridctrl?
A workaround is to sort the data before to insert them.



Yes, you can - but not so easy. Something to add in the new release. Now you can use GSort method (it's private so make it public first).

void GSort(int col, int order, int from, int count)

to sort the all rows:
grid.GSort(my_column, 0, grid.GetFixedCount(), grid.GetCount());

order can be 0,1 - less, 2 - greater

I will add simpler interface (similar to arrayctrl) in the next rc or final.

After sort call Repaint() to refresh the grid

[Updated on: Thu, 01 March 2007 15:51]

Report message to a moderator

Re: GridCtrl and sort at runtime [message #8301 is a reply to message #8299] Thu, 01 March 2007 16:45 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
unodgs wrote on Thu, 01 March 2007 15:49


Yes, you can - but not so easy. Something to add in the new release. Now you can use GSort method (it's private so make it public first).

void GSort(int col, int order, int from, int count)

to sort the all rows:
grid.GSort(my_column, 0, grid.GetFixedCount(), grid.GetCount());

order can be 0,1 - less, 2 - greater

I will add simpler interface (similar to arrayctrl) in the next rc or final.

After sort call Repaint() to refresh the grid




Unfortunately does not work. In the constructor I filled the grid and used Gsort
...
for (i=1; i<=TD.NPlayer; i++) arr.Add( player[i].RATING, player[i].name);
arr.GSort( 0, 2, arr.GetFixedCount(), arr.GetCount());
arr.Repaint();
...

But the order remain the same. I've used all type of order (0,1,2). BTW what is it GetFixedCount()?
Thanks,
Luigi
Re: GridCtrl and sort at runtime [message #8358 is a reply to message #8301] Mon, 05 March 2007 10:21 Go to previous message
unodgs is currently offline  unodgs
Messages: 1366
Registered: November 2005
Location: Poland
Ultimate Contributor

Sorry, you're right - it dosn't work. Anyway I've added Sort methods to GridCtrl - they will be available today in uvs and in rc3.

How to use them:

grid.Sort(0, GridCtrl::SORT_UP) - sorts the rows using values from column 0 (first non-fixed column) in up direction (lower values are on the top)

Id NAME("name");

grid.Sort(NAME) - the same, but column number is given as an Id, default sorting mode is SORT_UP

Sorting modes:

GridCtrl::SORT_UP - less values on the top
GridCtrl::SORT_DOWN - less values on the bottom
GridCtrl::SORT_ID - restore original row order

It is also possible to do "multisort":
grid.Sort(COL0, GridCtrl::SORT_UP, true)
    .Sort(COL5, GridCtrl::SORT_DOWN, true)
    .Sort(COL7, GridCtrl::SORT_UP, true);


Third parameter says we're doing multisort. If you don't like true/false arguments use MultiSort:

grid.MultiSort(COL0, GridCtrl::SORT_UP)
    .MultiSort(COL5, GridCtrl::SORT_DOWN)
    .MultiSort(COL7, GridCtrl::SORT_UP);


MultiSort does not refresh the grid by default! Use Repaint()

grid.MultiSort(COL0, GridCtrl::SORT_UP)
    .MultiSort(COL5, GridCtrl::SORT_DOWN)
    .MultiSort(COL7, GridCtrl::SORT_UP)
    .Repaint();


To switch off sorting and to restore original row order use ClearSort():

grid.ClearSort();

If you find any trouble report it please.


Previous Topic: Escaping cursor in gridctrl
Next Topic: just looking for a basic arrayctrl example please
Goto Forum:
  


Current Time: Mon Apr 29 08:17:36 CEST 2024

Total time taken to generate the page: 0.03079 seconds