Home » U++ Library support » ArrayCtrl, HeaderCtrl & GridCtrl » GridCtrl and sort at runtime
|
Re: GridCtrl and sort at runtime [message #8299 is a reply to message #8298] |
Thu, 01 March 2007 15:49 |
|
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 |
|
forlano
Messages: 1186 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 |
|
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.
|
|
|
Goto Forum:
Current Time: Thu May 23 17:31:57 CEST 2024
Total time taken to generate the page: 0.02331 seconds
|