Re: sorting in listview
If you are doing your sorting through that callback function, using
SortItems.
Then have flag for each column to know which way it is sorted (I would use a
CArray). In your CompareFunction callback, but the logic to handle this by
comparing all or some of the columns of the two items that it passes you.
This is a simple example to get you started.
typedef CArray<int> CSortArray;
//1 = up, 0 = none, -1 = down
m_SortOrderOfColumns.SetAt(SortByColumn,Up or Down);
m_ListCtrl.SortItems(CompareFunction,&m_SortOrderOfColumn);
int CALLBACK CompareFunction(LPARAM lParam1,LPARAM lParam2,LPARAM
lParamData)
{
CSortArray *pSortArray = (CSortArray *)lParamData;
int ReturnValue = 0; //they are equal to begin with
if (m_SortArray.GetAt(0) != 0)
{
ReturnValue = compare the two for that column asending or desending
}
else if (m_SortArray.GetAt(1) != 0)
{
}
return ReturnValue;
}
Hope this helps
AliR.
"AlGorr" <a@a.com> wrote in message news:e4skk6$f0i$1@news.tiscali.fr...
Hello,
I have Listview with 3 columns.
I have already implemented the columnClicked event, created a custom class
to take care of sorting on all columns (when column header is clicked).
Works fine...all is well.
BUT...what I would like to have now is the ability for the sort to
"stick".
I don't know how to articulate this better but I will try.
I wish to have sorting capabilities similar to the ORDER BY clause in a
SQL
statement where the columns act together as a sort function...
Let's say I have this Listview
type value name
1 10 a
2 6 b
3 5 c
4 10 d
5 1 z
4 12 a
1 3 b
In SQL, I can make a statement like this
SELECT * FROM myTable ORDER BY type, value, name
The results would be:
type value name
1 3 b
1 10 a
2 6 b
3 5 c
4 10 d
4 12 a
5 1 z
Right now in my listview, I can sort 1 column at a time. So If I click on
the "type" column it will sort it fine, but if I also want to sort by
value,
IN ADDITION TO the type column, that won't happen. As soon as I click on
the
"value" column, I will get these results.
type value name
5 1 z
1 3 b
3 5 c
2 6 b
1 10 a
4 10 d
4 12 a
So the first sort doesn't stick and is forgotten.
Any way to make these things stick?
A simple code that Manually does it ( a function call instead of
columnclicked event) with hardcoded column index will do nicely...because
I
already know what needs to be sorted and ultimately I don't want to give
the
user the ability to column click and sort. I want to "force" the sort
order.
Thanks!!!