VS 2010 Sorting listview-VBForums
Results 1 to 5 of 5

Thread: Sorting listview

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,259

    Sorting listview

    I have a listview that has multiple columns. I am wanting to sort these columns when clicking on the column header.

    I see there is a sort function, but am not having much luck in using it.

    How can i sort my listview when clicking on the column header?

  2. #2
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,925

    Re: Sorting listview

    Simon, Have you seen this msdn link?

    Topic: ListView.ColumnClick Event
    Link: http://msdn.microsoft.com/en-us/libr...lumnclick.aspx

    Or this?

    Topic: How to sort a ListView control by a column in Visual Basic .NET or in Visual Basic 2005
    Link: http://support.microsoft.com/kb/319399
    The poster formerly known as koolsid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,259

    Re: Sorting listview

    The second link works very well. One thing however, if one of my columns is an integer or a long, how can I easily modify the code to sort by the value of the number, and not just its first character?

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,259

    Re: Sorting listview

    Another thing... I am not sure why, but when I click on my 5th column, I get the following error:

    InvalidArgument=Value of '5' is not valid for 'index'.
    Parameter name: index
    I do not know why this happens... it is the exact code from the MSDN site. I have not had any problems with this before.

  5. #5
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    3,586

    Re: Sorting listview

    Quote Originally Posted by Simon Canning View Post
    The second link works very well. One thing however, if one of my columns is an integer or a long, how can I easily modify the code to sort by the value of the number, and not just its first character?
    I think you need to check the data type in your comparer class.
    FWIW I've used/modified this clsListviewSorter.vb class for a couple of my apps where I have columns of numbers, dates and strings, and use it like...
    Code:
    LV.ListViewItemSorter = New clsListviewSorter(Column, SortDirection)
    LV.Sort()
    LV.ListViewItemSorter = Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.