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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:57:16+00:00 2026-05-14T23:57:16+00:00

All I am doing is a simple: // Both the methods, order.GetAllOrderItems() and order.GetOrderedItemsWhereBrandIs(foo)

  • 0

All I am doing is a simple:

    // Both the methods, order.GetAllOrderItems() and order.GetOrderedItemsWhereBrandIs("foo")
    // return an IEnumerable<T> so the assignment to the DataSource property of the DataGridView
    // should be fine. The problem is in re-assigning the data source property.
    public void DisplayItems()
    {
        // The data appears if I have just this line.
        dgvOrderedItems.DataSource = order.GetAllOrderItems();

        dgvOrderedItems.DataSource = null;

        // This time the data grid does not take the new data source. Instead, because
        // of the null assignment in the previous statement, it displays no data at all.
        dgvOrderedItems.DataSource = order.GetOrderedItemsWhereBrandIs("Lenovo");
    }

My question is: is there a way to change the data source of a DataGridView control once it has been set? I am using C# 4.0 and Visual Studio 2010 for development.

  • 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-05-14T23:57:17+00:00Added an answer on May 14, 2026 at 11:57 pm

    Databinding cannot be used with IEnumerables; you can only bind to an IList or better.

    Add .ToArray() to turn the IEnumerable into an IList<T>.

    The reason it works the first time is probably because your GetAllOrderItems doesn’t perform any LINQ calls and ends up returning an object that implements IList.

    However, since your GetOrderedItemsWhereBrandIs method (presumably) includes a Where() call, it returns an object that only implements IEnumerable.

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

Sidebar

Related Questions

If all that you're doing is a simple one-pass iteration (i.e. only hasNext() and
I've been doing all people told me to make it works , but there
we're transitioning to doing all our task tracking in TFS 2010 and I'm wondering
I'm using rails, but doing all my Javascript unobtrusively using jQuery in application.js .
I'm deleting an item and want to pop-up a confirmation window before doing all
I'm in a project where it's pretty much my first time doing all the
I'm looking at a complex bit of JavaScript, which is doing all sorts of
All I am doing is finish of a wizard. On click of this, I
I've been doing this all the time: result = subprocess.call(['copy', '123*.xml', 'out_folder\\.', '/y']) if
OleDbDataAdapter internal error: invalid row set accessor: Ordinal=6 Status=UNSUPPORTEDCONVERSION All I'm doing is trying

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.