[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

Sort Column using CListCtl

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
kingservant
Asked:
kingservant
1 Solution
 
galkinCommented:
Look at "codeguru" site at http://www.codeguru.com/listview/listview_toc.shtml. There are several article about sorting of list view control
0
 
kingservantAuthor Commented:
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
 
Tommy HuiCommented:
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now