ReMEn wrote:
The code you provided works with no problems on columns with only integers or
only strings. However, I have a column with a mixed string containing both
letters and numbers. So when I click the header of the column containing the
mixed string, I get "Input string was not in correct format" error.
Any ideas around this?
Thanks
You define a compare function
=== snippet from my codes: ===
int CALLBACK ListCtrl::compareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
...
}
==============================
and call it from function reacting to LVN_COLUMNCLICK notifcation
=== snippet from my codes: ===
void ListCtrl::sortCol(int iCol) // dispatch LVN_COLUMNCLICK, iCol is ((LPNMLISTVIEW)lParam)->iSubItem
{
int param3;
...
ListView_SortItems( hwndLV, (PFNLVCOMPARE) ListCtrl::compareFunc, (LPARAM)(param3));
...
}
==============================
And it's your compare Function which decide how to sort the data.
In you case, the user interface need to remember the last option of sorting,
and decide which way to do next, and encode this info in the 3rd parameter of
the ListView_SortItems(). Your compareFunc should decode the parameter and
do (or call separate functions of) comparaison of the data.
Because these things is enough complecated, I wrote in separate ListCtrl class once
and forgot the the details for forever, happy to be a client user of my own class. :)
muchan