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. Sorting List View

Sorting List View

Scheduled Pinned Locked Moved C / C++ / MFC
algorithms
4 Posts 4 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.
  • B Offline
    B Offline
    BicycleTheif
    wrote on last edited by
    #1

    I have a list view which needs to be sorted based on a click on header.I am using the ListCtrl.SortItems() function. But it is crashing when i clicked on the header.For better understanding i have listed the code. void CDirTreeDemoView::OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*) pNMHDR; this->GetListCtrl().SortItems (CompareFunc, pNMListView->iSubItem); *pResult = 0; } int CALLBACK CDirTreeDemoView::CompareFunc (LPARAM lParam1, LPARAM lParam2,LPARAM lParamSort) { ITEMINFO* pItem1 = (ITEMINFO*) lParam1; ITEMINFO* pItem2 = (ITEMINFO*) lParam2; int nResult = 0; switch (lParamSort) { case 0: // File name nResult = pItem1->strFileName.CompareNoCase (pItem2->strFileName); break; case 1: // File size nResult = pItem1->nFileSizeLow - pItem2->nFileSizeLow; break; case 2: // Date and time nResult = ::CompareFileTime (&pItem1->ftLastWriteTime, &pItem2->ftLastWriteTime); break; } return nResult; } When i debuged lParam1 and lParam2 are getting value as '0'. Any hekp please Thanks

    J S D 3 Replies Last reply
    0
    • B BicycleTheif

      I have a list view which needs to be sorted based on a click on header.I am using the ListCtrl.SortItems() function. But it is crashing when i clicked on the header.For better understanding i have listed the code. void CDirTreeDemoView::OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*) pNMHDR; this->GetListCtrl().SortItems (CompareFunc, pNMListView->iSubItem); *pResult = 0; } int CALLBACK CDirTreeDemoView::CompareFunc (LPARAM lParam1, LPARAM lParam2,LPARAM lParamSort) { ITEMINFO* pItem1 = (ITEMINFO*) lParam1; ITEMINFO* pItem2 = (ITEMINFO*) lParam2; int nResult = 0; switch (lParamSort) { case 0: // File name nResult = pItem1->strFileName.CompareNoCase (pItem2->strFileName); break; case 1: // File size nResult = pItem1->nFileSizeLow - pItem2->nFileSizeLow; break; case 2: // Date and time nResult = ::CompareFileTime (&pItem1->ftLastWriteTime, &pItem2->ftLastWriteTime); break; } return nResult; } When i debuged lParam1 and lParam2 are getting value as '0'. Any hekp please Thanks

      J Offline
      J Offline
      Jose Lamas Rios
      wrote on last edited by
      #2

      Silly question, but... Are you setting lParam when inserting the items in the list? -- jlr http://jlamas.blogspot.com/[^]

      1 Reply Last reply
      0
      • B BicycleTheif

        I have a list view which needs to be sorted based on a click on header.I am using the ListCtrl.SortItems() function. But it is crashing when i clicked on the header.For better understanding i have listed the code. void CDirTreeDemoView::OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*) pNMHDR; this->GetListCtrl().SortItems (CompareFunc, pNMListView->iSubItem); *pResult = 0; } int CALLBACK CDirTreeDemoView::CompareFunc (LPARAM lParam1, LPARAM lParam2,LPARAM lParamSort) { ITEMINFO* pItem1 = (ITEMINFO*) lParam1; ITEMINFO* pItem2 = (ITEMINFO*) lParam2; int nResult = 0; switch (lParamSort) { case 0: // File name nResult = pItem1->strFileName.CompareNoCase (pItem2->strFileName); break; case 1: // File size nResult = pItem1->nFileSizeLow - pItem2->nFileSizeLow; break; case 2: // Date and time nResult = ::CompareFileTime (&pItem1->ftLastWriteTime, &pItem2->ftLastWriteTime); break; } return nResult; } When i debuged lParam1 and lParam2 are getting value as '0'. Any hekp please Thanks

        S Offline
        S Offline
        SVPG
        wrote on last edited by
        #3

        This link should help http://www.codeproject.com/buglist/listcontrolsortitemsbug.asp

        1 Reply Last reply
        0
        • B BicycleTheif

          I have a list view which needs to be sorted based on a click on header.I am using the ListCtrl.SortItems() function. But it is crashing when i clicked on the header.For better understanding i have listed the code. void CDirTreeDemoView::OnColumnClick(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*) pNMHDR; this->GetListCtrl().SortItems (CompareFunc, pNMListView->iSubItem); *pResult = 0; } int CALLBACK CDirTreeDemoView::CompareFunc (LPARAM lParam1, LPARAM lParam2,LPARAM lParamSort) { ITEMINFO* pItem1 = (ITEMINFO*) lParam1; ITEMINFO* pItem2 = (ITEMINFO*) lParam2; int nResult = 0; switch (lParamSort) { case 0: // File name nResult = pItem1->strFileName.CompareNoCase (pItem2->strFileName); break; case 1: // File size nResult = pItem1->nFileSizeLow - pItem2->nFileSizeLow; break; case 2: // Date and time nResult = ::CompareFileTime (&pItem1->ftLastWriteTime, &pItem2->ftLastWriteTime); break; } return nResult; } When i debuged lParam1 and lParam2 are getting value as '0'. Any hekp please Thanks

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          When populating the list, are you also calling SetItemData()?


          "One must learn from the bite of the fire to leave it alone." - Native American Proverb

          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