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

  • Home
  • SEARCH
  • 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 9141579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:39:49+00:00 2026-06-17T09:39:49+00:00

I’m using Entity Framework (EF), and have a BindingList I can get from the

  • 0

I’m using Entity Framework (EF), and have a BindingList I can get from the context (using the DbExtensions.ToBindingList method), and I have a form with a DataGridView.

The objective is to display the contents of the EF table on the DataGridView, so I have the following code in the form’s constructor to set the DataGridView‘s DataSource to a BindingSource and that BindingSource‘s DataSource to the BindingList from EF:

categoryBindSrc.DataSource = _context.Categories.Local.ToBindingList();
categoryDataGrid.Sort(categoryDataGrid.Columns["categorySortIdColumn"], ListSortDirection.Ascending);

Before that, in the Form’s generated code, these lines exist:

categoryDataGrid.DataSource = categoryBindSrc;
categorySortIdColumn.DataPropertyName = "SortId";

This code is in the form’s constructor, but when I run it, I get the following exception (I truncated the stack trace):

System.InvalidOperationException was unhandled
HResult=-2146233079
Message=DataGridView control must be bound to an IBindingList object to be sorted.
Source=System.Windows.Forms
StackTrace:
    at System.Windows.Forms.DataGridView.SortDataBoundDataGridView_PerformCheck(DataGridViewColumn dataGridViewColumn)
    at System.Windows.Forms.DataGridView.SortInternal(IComparer comparer, DataGridViewColumn dataGridViewColumn, ListSortDirection direction)
    at System.Windows.Forms.DataGridView.Sort(DataGridViewColumn dataGridViewColumn, ListSortDirection direction)

To my understanding, BindingList does implement IBindingList so that shouldn’t be the problem. The Sort method says the DataGridView must be data-bound (it is) and that the sort-by-column’s DataPropertyName property is set (it is) which causes the column’s IsDataBound property to return true (when debugging it shows false in the watch window)

It seems that the problem is that IsDataBound isn’t getting updated, but I don’t know what SortDataBoundDataGridView_PerformCheck (the method that threw the exception) checks for exactly, or why IsDataBound wouldn’t be set.

I tried to provide all the code you need to understand the question, but let me know if you need more. I also checked several related questions on S/O–none of the answers helped.

EDIT: It appears I can call Sort just fine from any other method except the constructor. This might be a threading issue.

  • 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-17T09:39:49+00:00Added an answer on June 17, 2026 at 9:39 am

    Looks like the line categoryBindSrc.DataSource = _context.Categories.Local.ToBindingList(); must be calling another thread that hasn’t finished when Sort is called, so a couple of properties that are checked by SortDataBoundDataGridView_PerformCheck haven’t been updated yet.

    Therefore, the solution is to call the method after that thread has finished. A nice place to put it so it still achieves its affect of sorting the data members before the users sees them is by overriding the form’s OnLoad method and calling Sort there.

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

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string
I have thousands of HTML files to process using Groovy/Java and I need to
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am using jsonparser to parse data and images obtained from json response. When
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.