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. How to sort the rows of CListCtrl

How to sort the rows of CListCtrl

Scheduled Pinned Locked Moved C / C++ / MFC
algorithmstutorial
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.
  • A Offline
    A Offline
    anilksingh
    wrote on last edited by
    #1

    How to sort the rows of CListCtrl depanding upon Particular column. Or Please tell me how to use CListCtrl::SortItems function for sorting.

    _ D 2 Replies Last reply
    0
    • A anilksingh

      How to sort the rows of CListCtrl depanding upon Particular column. Or Please tell me how to use CListCtrl::SortItems function for sorting.

      _ Offline
      _ Offline
      _AnsHUMAN_
      wrote on last edited by
      #2

      Hi Anil, you need to create a callback function that will be called each time the two items in the list control need to be compared. int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort); BOOL SortItems( PFNLVCOMPARE pfnCompare, DWORD_PTR dwData ); Pass a pointer to the sort items function for the callback function. Vision is Always important and so is your ATTITUDE. Wishes. Anshuman Dandekar

      N 1 Reply Last reply
      0
      • _ _AnsHUMAN_

        Hi Anil, you need to create a callback function that will be called each time the two items in the list control need to be compared. int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort); BOOL SortItems( PFNLVCOMPARE pfnCompare, DWORD_PTR dwData ); Pass a pointer to the sort items function for the callback function. Vision is Always important and so is your ATTITUDE. Wishes. Anshuman Dandekar

        N Offline
        N Offline
        Naveen
        wrote on last edited by
        #3

        _AnShUmAn_ wrote:

        BOOL SortItems( PFNLVCOMPARE pfnCompare, DWORD_PTR dwData );

        The above function internally sends the LVM_SORTITEMS message.. I found the LVM_SORTITEMSEX message is more easy to use than LVM_SORTITEMS . U can use ListView_SortItemsEx Macro to send LVM_SORTITEMSEX message nave

        1 Reply Last reply
        0
        • A anilksingh

          How to sort the rows of CListCtrl depanding upon Particular column. Or Please tell me how to use CListCtrl::SortItems function for sorting.

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

          anilksingh wrote:

          How to sort the rows of CListCtrl depanding upon Particular column.

          Provide a HDN_ITEMCLICK handler. In that handler function, the column that was clicked is:

          HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
          m_nSortColumn = phdn->iItem;

          Now call SortItems().

          anilksingh wrote:

          Or Please tell me how to use CListCtrl::SortItems function for sorting.

          Be sure to call SetItemData() when adding items to the list control.


          "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

          "We will be known forever by the tracks we leave." - 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