Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CListCtrl sorting ...

Posted on 1997-03-10
1
Medium Priority
?
334 Views
Last Modified: 2008-03-03
how do I set up a list control to allow simle alphanumeric
sorting when the column title button is clicked .

i.e. Just like the windows explorer columns.

Should I be using the more simpler CViewList.?
0
Comment
Question by:georgeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
MFCGuy earned 100 total points
ID: 1161899
First, set up your ListCtrl rows to have an LParam (SetItemData()) that means something for the sort
like a pointer to the object you want to sort on.
I used an object in the example below.

Insert the following code:

in .h
-----
static int CALLBACK ListCtrlCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);

in .cpp
-------
int CALLBACK CODListCtrl::ListCtrlCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
      //If LPARAMs are invalid, return 0 (sort items are equal)
      if(lParam1 == 0 || lParam2 == 0)
            return 0;
        int column = (int) lParamSort;

      CMyObject* s1 = (CMyObject*)lParam1;
      CMyObject* s2 = (CMyObject*)lParam2;
//I'm only sorting column 0 here...
        if(column == 0)      //default - compare as CStrings
             return s1->m_aString.Compare(s2->m_aString);
        return 0;//rows matched
}

Call the function in your .cpp when the user clicks on a column
by using:
CListCtrl::SortItems(ListCtrlCompareProc, <the column that was sorted on>);

This will sort in ascending order.

Hope that gave you enough to get you going...

Regards,
MFCGuy
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question