Solved

Sort Column using CListCtl

Posted on 1998-02-12
3
228 Views
Last Modified: 2008-02-01
I'm using MSVC++4.1.  I have a CListCtl (Report View) class and I can't figure out how to use the SortItems() function with the Callback routine if the user were to click on a column. I was wondering if I could get some coding examples on how to do this.
0
Comment
Question by:kingservant
3 Comments
 
LVL 7

Expert Comment

by:galkin
ID: 1181893
Look at "codeguru" site at http://www.codeguru.com/listview/listview_toc.shtml. There are several article about sorting of list view control
0
 

Author Comment

by:kingservant
ID: 1181894
The examples on that web site didn't quite have the solution I needed.  I guess what I am looking for is examples on using the CListCtrl column click message to invoke my sort using SortItems().
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 80 total points
ID: 1181895
Here is an excerpt from one of my programs:

void CGuidListCtrl::OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult)
{
      NM_LISTVIEW* pNMListView = reinterpret_cast<NM_LISTVIEW*>(pNMHDR);
      int curSortCol = pNMListView->iSubItem;

      OnColumnClickImp(curSortCol);

      SortFields();
      *pResult = 0;
}

void CGuidListCtrl::SortFields()
{
      CWaitCursor wait;
      SortItems(SortCB, reinterpret_cast<LPARAM>(this));
}

int CALLBACK CGuidListCtrl::SortCB(LPARAM item1, LPARAM item2, LPARAM itemData)
{
      CGuidListCtrl* This = reinterpret_cast<CGuidListCtrl*>(itemData);

      int itemIndex1 = This->GetListIndexOfItemData(item1);
      ASSERT(itemIndex1 != -1);
      CString text1 = This->GetItemText(itemIndex1, This->GetSortColumn());

      int itemIndex2 = This->GetListIndexOfItemData(item2);
      ASSERT(itemIndex2 != -1);
      CString text2 = This->GetItemText(itemIndex2, This->GetSortColumn());

      if (This->IsSortAscending())
            return text1.CompareNoCase(text2);
      else
            return text2.CompareNoCase(text1);

      return 0;
}

0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

821 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