Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CListCtrl::SortItems problem

CListCtrl::SortItems problem

Scheduled Pinned Locked Moved C / C++ / MFC
help
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wim Jans
    wrote on last edited by
    #1

    I'm trying to mimick the 'arrange icons by...' as seen in explorer in my CListView based app. I've looked up the method to implement this on msdn and have implemented my sort routine. So far so good... The problem I have is that in mY sort function (compare function) I always receive the first record (0) of my listview to compare. Some code snippits to explain: void CMylistView::OnViewBydescr() { CListCtrl* m_cListCtrl; m_cListCtrl=&GetListCtrl(); m_cListCtrl->SortItems(SortFunction, (LPARAM)(m_cListCtrl)); } int CALLBACK CMylistView::SortFunction(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { CListCtrl* pListCtrl = (CListCtrl*) lParamSort; CString strItem1 = pListCtrl->GetItemText(lParam1, 0); CString strItem2 = pListCtrl->GetItemText(lParam2, 0); return strcmp(strItem1, strItem2); }

    W M 2 Replies Last reply
    0
    • W Wim Jans

      I'm trying to mimick the 'arrange icons by...' as seen in explorer in my CListView based app. I've looked up the method to implement this on msdn and have implemented my sort routine. So far so good... The problem I have is that in mY sort function (compare function) I always receive the first record (0) of my listview to compare. Some code snippits to explain: void CMylistView::OnViewBydescr() { CListCtrl* m_cListCtrl; m_cListCtrl=&GetListCtrl(); m_cListCtrl->SortItems(SortFunction, (LPARAM)(m_cListCtrl)); } int CALLBACK CMylistView::SortFunction(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { CListCtrl* pListCtrl = (CListCtrl*) lParamSort; CString strItem1 = pListCtrl->GetItemText(lParam1, 0); CString strItem2 = pListCtrl->GetItemText(lParam2, 0); return strcmp(strItem1, strItem2); }

      W Offline
      W Offline
      Wim Jans
      wrote on last edited by
      #2

      Solved it! I changed m_cListCtrl->SortItems(SortFunction, (LPARAM)(m_cListCtrl)); into ListView_SortItemsEx(GetSafeHwnd(), SortFunction, (LPARAM) this); But why doesn't the m_cListCtrl->SortItems doesn't work :confused: Wim

      1 Reply Last reply
      0
      • W Wim Jans

        I'm trying to mimick the 'arrange icons by...' as seen in explorer in my CListView based app. I've looked up the method to implement this on msdn and have implemented my sort routine. So far so good... The problem I have is that in mY sort function (compare function) I always receive the first record (0) of my listview to compare. Some code snippits to explain: void CMylistView::OnViewBydescr() { CListCtrl* m_cListCtrl; m_cListCtrl=&GetListCtrl(); m_cListCtrl->SortItems(SortFunction, (LPARAM)(m_cListCtrl)); } int CALLBACK CMylistView::SortFunction(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) { CListCtrl* pListCtrl = (CListCtrl*) lParamSort; CString strItem1 = pListCtrl->GetItemText(lParam1, 0); CString strItem2 = pListCtrl->GetItemText(lParam2, 0); return strcmp(strItem1, strItem2); }

        M Offline
        M Offline
        Michael Dunn
        wrote on last edited by
        #3

        Two problems. First, change

        SortItems ( SortFunction, (LPARAM) m_cListCtrl )

        to

        SortItems ( SortFunction, (LPARAM) &m_cListCtrl ) // add ampersand

        Second, you are thinking lParam1 and lParam2 are the item indexes, but they are not, they are the lParam data associated with the two items being compared. They are always 0 because you probably don't use those data members. --Mike-- PROCRASTINATION: Hard work often pays off after time, but laziness always pays off now. BUY MY SOFTWARE!! (please?) RightClick-Encrypt - file encryption w/Explorer plugins | 1ClickPicGrabber - web page picture grabber for IE My IntarWeb Homepgae!!!11

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups