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 » How to sort the ArrCtrl [SOLVED]
How to sort the ArrCtrl [SOLVED] [message #2228] Tue, 04 April 2006 18:50 Go to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
In the ArrCtrl documentation there are many Sort methods with obscure (for me) syntax.

I can avoid all of them with the following approach:
1) get the record from the array
2) sort them
3) clear the array
4) put the sorted record in the array.

But I am sure there is shortcut for it thought for lazy man. Just I would like to click on the header of the array and it show the new order. Is there somebody (I know who Smile ) that can show one minimalist example?

Thank you,
Luigi

[Updated on: Mon, 01 May 2006 10:25] by Moderator

Report message to a moderator

Re: How to sort the ArrCtrl [message #2239 is a reply to message #2228] Wed, 05 April 2006 03:08 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
forlano wrote on Tue, 04 April 2006 17:50

In the ArrCtrl documentation there are many Sort methods with obscure (for me) syntax.

I can avoid all of them with the following approach:
1) get the record from the array
2) sort them
3) clear the array
4) put the sorted record in the array.

But I am sure there is shortcut for it thought for lazy man. Just I would like to click on the header of the array and it show the new order. Is there somebody (I know who Smile ) that can show one minimalist example?

Thank you,
Luigi


You are not lazy enough once again! Smile 4 Operations!!! and so difficult?! You must avoid such thinking with Ultimate++... Smile

Why not to start with easy things:
arr.Sort(int_col);

P.S. Sorry for the delay - I didn't want you to die so soon..

[Updated on: Wed, 05 April 2006 03:42]

Report message to a moderator

Re: How to sort the ArrCtrl [message #2272 is a reply to message #2239] Wed, 05 April 2006 16:21 Go to previous messageGo to next message
forlano is currently offline  forlano
Messages: 1185
Registered: March 2006
Location: Italy
Senior Contributor
fudadmin wrote on Wed, 05 April 2006 03:08


You are not lazy enough once again! Smile 4 Operations!!! and so difficult?! You must avoid such thinking with Ultimate++... Smile

Why not to start with easy things:
arr.Sort(int_col);

P.S. Sorry for the delay - I didn't want you to die so soon..


Only now I have had the chance to try it. I couldn't believe that this line was the solution. I've attached the following method

void Tab1::SortRecord() // body of the callback 
{ arr.Sort(0);
}


to a button and it worked! Surprised .
If I put your line inside the AddPlayer method the array is always sorted. I prefer to see the added recod at the end and then sort when I need. So the decision of a new method... and new button...

This is really the perfect tool for lazy people. I can become mad if I remind the time lost to reinvent the wheel with other tool. I suspect my application ported to U++ will be long maybe 1/5 of the previous one.

But this is not what I wanted! In fact I wanted to click on the 'header' to get an array sorted. So I started to think in a lazy way... to prevent future complain Laughing . After some investigation I got the answer:

void Tab1::SortRecord() 
{ int i;
  i = arr.GetClickColumn();     
  arr.Sort( i );
}


associated to doubleclick event in the constructor

arr.WhenLeftDouble = THISBACK(SortRecord);

This is even better from point of view of lazyness because I do not need to move the mouse up to the header of the array when I am at its bottom (notoriously a very time and energy comsuming task). I hope you agree Smile

Luigi
Re: How to sort the ArrCtrl [message #2275 is a reply to message #2272] Wed, 05 April 2006 17:49 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Sorry, that is wrong. GetClickColumn returns the column, but only if you click at "cells".

What you need to use is WhenAction of HeaderCtrl::Column like this:

   array.AddColumn("MyColumn").HeaderTab().WhenAction = THISBACK(SortByColumn);


BTW, quite handy here is using THISBACK1, because that way you can pass column index:

void MyApp::SortColumn(int column)
{
   array.Sort(i);
}

.....
   array.AddColumn("MyColumn1").HeaderTab().WhenAction = THISBACK1(SortByColumn, 0);
   array.AddColumn("MyColumn2").HeaderTab().WhenAction = THISBACK1(SortByColumn, 1);


Mirek
Re: How to sort the ArrCtrl [message #2276 is a reply to message #2275] Wed, 05 April 2006 18:03 Go to previous messageGo to next message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
luzr wrote on Wed, 05 April 2006 16:49

Sorry, that is wrong. GetClickColumn returns the column, but only if you click at "cells".

What you need to use is WhenAction of HeaderCtrl::Column like this:

   array.AddColumn("MyColumn").HeaderTab().WhenAction = THISBACK(SortByColumn);


BTW, quite handy here is using THISBACK1, because that way you can pass column index:

void MyApp::SortColumn(int column)
{
   array.Sort(i);
}

.....
   array.AddColumn("MyColumn1").HeaderTab().WhenAction = THISBACK1(SortByColumn, 0);
   array.AddColumn("MyColumn2").HeaderTab().WhenAction = THISBACK1(SortByColumn, 1);


Mirek


Mirek,
You have been faster than me! Twisted Evil
You have too much free time... Laughing
... Wink
Re: How to sort the ArrCtrl [message #2277 is a reply to message #2276] Wed, 05 April 2006 18:12 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Quote:

You have been faster than me! Twisted Evil
You have too much free time... Laughing
... Wink


Yes, when I am _supposed_ to do my "money" work, I have usually a plenty of time responding to forum Smile Which will inevitably result to lagging my work progress, being awake for too long and sleeping for only 5 hours... again... Sad

Mirek
Re: How to sort the ArrCtrl [message #2279 is a reply to message #2277] Wed, 05 April 2006 18:43 Go to previous message
fudadmin is currently offline  fudadmin
Messages: 1321
Registered: November 2005
Location: Kaunas, Lithuania
Ultimate Contributor
Administrator
luzr wrote on Wed, 05 April 2006 17:12

Quote:

You have been faster than me! Twisted Evil
You have too much free time... Laughing
... Wink


Yes, when I am _supposed_ to do my "money" work, I have usually a plenty of time responding to forum Smile Which will inevitably result to lagging my work progress, being awake for too long and sleeping for only 5 hours... again... Sad

Mirek


Mirek, you know that I'm really concerned about your wellbeing. That's why I'm trying to learn as much, and as quickly, as possible myself to help the Ultimate++ cause.
You don't have to respond in these "Forlano lessons" immediately. I'm trying to teach with some fun aspect and also let Luigi to discover some things himself while sometimes only providing just hints.
Anyway, thanks a lot once again and care yourself!
Previous Topic: ArrayCtrl crashes with "embedded" Ctrls referenced by Id [SOLVED]
Next Topic: ArrayCtrl - how to set tooltips? [BY DERIVING...]
Goto Forum:
  


Current Time: Mon Apr 29 15:34:07 CEST 2024

Total time taken to generate the page: 0.02101 seconds