Solved

Sort Column using CListCtl

Posted on 1998-02-12
3
206 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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…
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 additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now