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 8427839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:53:21+00:00 2026-06-10T04:53:21+00:00

I have a data-bound DataGridView that I am trying to sort using an IComparer.

  • 0

I have a data-bound DataGridView that I am trying to sort using an IComparer.

When I try to apply my sort I get this error:

DataGridView control is data-bound. The control cannot use the comparer to perform the sort operation.

My sorting technique was based off this link.

Just an FYI I am trying to compare Bitmaps by using their tag values.

public int Compare(object x, object y)
{
    DataGridViewRow DataGridViewRow1 = (DataGridViewRow)x;
    DataGridViewRow DataGridViewRow2 = (DataGridViewRow)y;

    // Try to sort based on the tag 
    int CompareResult = System.String.Compare(
        DataGridViewRow1.Cells[1].Tag.ToString(),
        DataGridViewRow2.Cells[1].Tag.ToString());



    return CompareResult * sortOrderModifier;
}
  • 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-10T04:53:22+00:00Added an answer on June 10, 2026 at 4:53 am

    As far as I know, databound DatagridView cannot be sorted using the methods shown on the linked article.

    What you want to do is sort the underlying container. If you’re using a DataTable, you can’t sort it directly.

    What you can do is use Linq’s OrderBy and pass it your custom comparer. After that, call AsDataView() on your linq query and bind your DataGridView to this DataView.

    Something like this:

     RowComparer comp = new RowComparer();
     var query = northwindDataSet.Customers.AsEnumerable().OrderBy(q => q, comp);
     DataView dv = query.AsDataView();
    
     customersBindingSource.DataSource = dv;
    

    Note that I’m using a DataTable and a BindingSource in this example, but you should get the idea 🙂

    Hope this helps

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

Sidebar

Related Questions

My DataGridView control currently sorts using the Sort property of the bound data, but
I have a repeater that's bound to a SQL Data Source (using ASP.NET). Are
I have data bound DataGridView in a desktop app with columns that have their
I have a data bound listbox that lists names of items, I am now
I use ADO.NET Entity-Framework, I have a page that is data-bound to an entity
Assume that I have the ItemSource bound and i am getting the data. Now
This is what I am trying to achieve: DataTable populated using data from non
I have a DataGridView that is bound to a DataTable, it has a column
I Have a Datagridview bound to a datatable wich hold data from a database
I have a datagridview which is bound to some data. One of the fields

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.