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#
  4. How to sort ListView items of some column.

How to sort ListView items of some column.

Scheduled Pinned Locked Moved C#
tutorial
3 Posts 3 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.
  • S Offline
    S Offline
    Saikek
    wrote on last edited by
    #1

    Hello, my cybrenetics Friends !!! I have a listview, and o wan't to sort the list by clicking the Column header. But i have 2 columns, and i wan't to sort the list by clicking the 2 column, so i can get the items sorted by the second raw. Thanks!!!

    One nation - underground

    B R 2 Replies Last reply
    0
    • S Saikek

      Hello, my cybrenetics Friends !!! I have a listview, and o wan't to sort the list by clicking the Column header. But i have 2 columns, and i wan't to sort the list by clicking the 2 column, so i can get the items sorted by the second raw. Thanks!!!

      One nation - underground

      B Offline
      B Offline
      BoneSoft
      wrote on last edited by
      #2

      There are several ways you could do this. But you'll likely want to create an IComparer implementation to look at ListViewItems, or whatever type you stick in the ListViewItem's Tag property. When you add an event handler for the ListView's ColumnClick event, the ColumnClickEventArgs instance gives you the index of the column clicked. You can use that in your IComparer to determine how to sort objects. In your handler, update or create a new comparer and set the ListView's ListViewItemSorter property with the instance you updated or created. Google IComparer to see how to implement one, but it's not difficult.

      private void listView1_ColumnClick(object sender, ColumnClickEventArgs e) {
      IComparer sorter = new YOURICOMPARER(e.Column)
      listView1.ListViewItemSorter = sorter;
      listView1.Sort();
      }


      Try code model generation tools at BoneSoft.com.

      1 Reply Last reply
      0
      • S Saikek

        Hello, my cybrenetics Friends !!! I have a listview, and o wan't to sort the list by clicking the Column header. But i have 2 columns, and i wan't to sort the list by clicking the 2 column, so i can get the items sorted by the second raw. Thanks!!!

        One nation - underground

        R Offline
        R Offline
        rahvyn6
        wrote on last edited by
        #3

        Check this article out, I think its what you're looking for: http://support.microsoft.com/kb/319401[^]

        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