Results 1 to 2 of 2

Thread: Listview Sorting In VB 2008 Issue <===

  1. #1
    TeachMe is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5
    Join Date
    Jun 2012
    Posts
    5
    Reputation
    0

    Question Listview Sorting In VB 2008 Issue <===

    I'm trying to make the listview sort the green "Yes!" to the top via a column "Click:" option and then the red "No" will be sorted to the bottom. We will need to make sure that the subitems will stay together.
    Here's an example of what I'm trying to accomplish:

    I would appreciate a code example if you can. Thanks.

  2. #2
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,188
    Reputation
    2368
    As explained in ListView.ListViewItemSorter Property (System.Windows.Forms) help page you have to write a class than implements IComparer and assign an instance of that to ListViewItemSorter property. The IComparer.Compare method compares two ListViewItem objects x and y, for example like this:
                Dim a = CType(x, ListViewItem).SubItems(1).Text
    Dim b = CType(y, ListViewItem).SubItems(1).Text
    Return b.CompareTo(a)

Tags for this Thread

Bookmarks

Posting Permissions

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