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 » ArrayCtrl sorting
ArrayCtrl sorting [message #13274] Fri, 28 December 2007 10:42 Go to next message
michael is currently offline  michael
Messages: 153
Registered: May 2007
Location: Germany
Experienced Member
What is the best method to sort an ArrayCtrl?

array.sort(column)?
array.SetSortColumn(int ii, bool descending = false)?

If i use array.sort(column), how can i set the sort order?

Or is SetSortColumn or ToggleSortColumn(int ii) the better way to sort an ArrayCtrl?

It would be nice if someone could provide an example how to change the sort order of an ArrayCtrl.
Re: ArrayCtrl sorting [message #13310 is a reply to message #13274] Mon, 31 December 2007 18:48 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
michael wrote on Fri, 28 December 2007 04:42

What is the best method to sort an ArrayCtrl?

array.sort(column)?
array.SetSortColumn(int ii, bool descending = false)?

If i use array.sort(column), how can i set the sort order?

Or is SetSortColumn or ToggleSortColumn(int ii) the better way to sort an ArrayCtrl?

It would be nice if someone could provide an example how to change the sort order of an ArrayCtrl.


SetSortColumn is more for GUI/user sorting (user clicks on column he wants to sort).

Use .Sort. That way you can use "Order" variant to provide more complex sorting predicate (based on all columns).

Mirek
Re: ArrayCtrl sorting [message #13313 is a reply to message #13310] Mon, 31 December 2007 19:35 Go to previous messageGo to next message
michael is currently offline  michael
Messages: 153
Registered: May 2007
Location: Germany
Experienced Member
Thanks, Mirek.

But i didn't understand how to use Order. Can you please explain this?

Michael
Re: ArrayCtrl sorting [message #13319 is a reply to message #13313] Tue, 01 January 2008 11:01 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
michael wrote on Mon, 31 December 2007 13:35

Thanks, Mirek.

But i didn't understand how to use Order. Can you please explain this?

Michael


E.g. like this:

struct DatumJmenoOrder : public ArrayCtrl::Order {
	virtual bool operator()(const Vector<Value>& row1, const Vector<Value>& row2) const
	{
		int q;
		q = (Date)row1[0] - (Date)row2[0];
		if(q) return q < 0;
		q = CompareJmeno(row1, row2, 1);
		if(q) return q < 0;
		q = CompareAdresa(row1, row2, 4);
		return q < 0;
	}
};


Compares based on 3 rows, with specific comparisons used for two of them...

Mirek
Previous Topic: Selection changes before LostFocus() is called
Next Topic: How to change GridCtrl background color
Goto Forum:
  


Current Time: Sat Apr 27 12:42:36 CEST 2024

Total time taken to generate the page: 0.05079 seconds