Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8140991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:20:51+00:00 2026-06-06T12:20:51+00:00

I want to sort ListView items by the content of second column (which can

  • 0

I want to sort ListView items by the content of second column (which can be either “Online” or “Offline”). Sorting will be done only in one specific place in code, so the solution doesn’t have to be flexible. More than that, it should be easy to implement and not requiring major changes in rest of application.

I tried to make class implementing IComparer and assign it to listView.ListViewItemSorter, but it doesn’t work for me.

Code sample:

class ChannelSorter : System.Collections.IComparer
{
    public int Compare(object a, object b)
    {
        if ((a as ListViewItem).SubItems[0].Text.CompareTo("Online") == 0)
            if ((b as ListViewItem).SubItems[0].Text.CompareTo("Online") == 0)
                return 0;
            else
                return -1;
        else if ((b as ListViewItem).SubItems[0].Text.CompareTo("Online") == 0)
            return 1;
        else
            return 0;
    }
}


// in constructor of Form1
listView1.ListViewItemSorter = new ChannelSorter();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T12:20:52+00:00Added an answer on June 6, 2026 at 12:20 pm

    You can use LINQ, with the OrderBy method:

    I suppose your users in the list are coming from an User[] array or a List, or any Enumerable. You then simply use the OrderBY method to get a new ordered List:

    var currentUsers = new List<User>();
    // Fill your users
    // Super happy fun sorting time!
    var sortedUsers = currentUsers.OrderBy(user => user.State);
    

    Where user.State is their current state (Online, Offline)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to sort the items inside column of ListView, i already made it,
I use a ListView with android.R.layout.simple_list_item_multiple_choice as list items. I want to sort the
I have been trying to create a ListView which I can sort using drag
I want to sort items where the comparison is performed by humans: Pictures Priority
I want to sort on a certain column only for rows containing a certain
I want to implement search bar in my application which will filter list view
I want to sort a bunch of files. I can do sort file.txt >
I want to sort a ListView control in C# based on columns. I have
I have a ListView (GridView) that I want to sort by 2 columns, so
I have a simple ListView and want to sort the contents numerically or alphabetically,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.