none
Is there a way to sort rows of a Listview Container on some but not all columns?

    Question

  • I need to sort all rows using three of four columns row data as the sort arguments and keeping the fourth column contents in it's proper row.  Thanks for any pointers to documentation on how to accomplish this. 

    Gene

    Monday, February 11, 2019 12:15 AM

Answers

  • Thanks.

    The intent is to sort on the first three columns and carry the fourth along but not consider it in the sort.

    I found a rather cheap way to accomplish it by building an spreadsheet and inserting a macro into it using the VB.Net program I am writing. 


    Gene

    Monday, February 11, 2019 10:57 PM

All replies

  • Hello,

    One idea is to write a ListViewItemComparer class as per the following class as a jump off/starting point.

    See second reply done in VB.NET

    https://stackoverflow.com/questions/1606644/sorting-a-listview-by-multiple-columns-in-c-sharp

    This one uses the same idea

    http://www.componentowl.com/documentation/better-listview/data/chapter-sort.html


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, February 11, 2019 12:22 AM
    Moderator
  • I need to sort all rows using three of four columns row data as the sort arguments and keeping the fourth column contents in it's proper row.  Thanks for any pointers to documentation on how to accomplish this. 

    Gene

     It is not quite clear to me exactly what you want to do.  Are you saying that you want to use the data from 3 or 4 columns all combined together to figure out the sorting order for the rows,  or do you just want to use 1 column's data at a time to sort the rows?

     If you want to sort them depending on one specified column at a time,  then creating a ListView column sorter as Karen has mentioned.  I have also posted an example of one that can sort by String,  Integer,  or Date values in the columns.  You can see the example in post #9 at This Link.  You could check the column index or name in the ListView1_ColumnClick event so you only let a new sort occur when the desired columns are clicked.

     However,  if you need to use the data from all 3 or 4 columns at the same time to sort the rows,  then we would need to know what kind of data are in these columns and how they would be combined for sorting.  This would likely need to be a specifically written sorting code.

     The last subitem in each row would move with the ListViewItem (Row) that it belongs to.  I you want them to stay in the row where they are while the rest of the subitems move to the sorting order,  that would also need to be a specifically written code to switch the subitems to the ListViewItem (row) that it matches up to with the new sort order.

     We will wait to hear a little more details and info on the specifics from you,  or if the standard sorter is what you really wanted....


    If you say it can`t be done then i`ll try it

    • Edited by IronRazerz Monday, February 11, 2019 7:22 PM
    Monday, February 11, 2019 6:47 PM
  • Thanks so much for your help.  I found a much simpler and cheaper way to do it.  Since this is a single user project (me) I picked the less elegant way to go. 

    Gene


    Monday, February 11, 2019 10:54 PM
  • Thanks.

    The intent is to sort on the first three columns and carry the fourth along but not consider it in the sort.

    I found a rather cheap way to accomplish it by building an spreadsheet and inserting a macro into it using the VB.Net program I am writing. 


    Gene

    Monday, February 11, 2019 10:57 PM
  • Hi,

    I am glad you have got your solution, we appreciated you shared us your solution and mark it as an answer.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 12, 2019 6:57 AM
    Moderator