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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:28:42+00:00 2026-05-13T08:28:42+00:00

I tried to bind List<T> to DataGridView . Everything seemed to be ok before

  • 0

I tried to bind List<T> to DataGridView. Everything seemed to be ok before I implemented deleting rows:

Companies.CompaniesList.RemoveAt(dataGridView1.SelectedRows[0].Index);
dataGridView1.DataSource = Companies.CompaniesList;

(Companies.Companies is List<Company> collection)
What I’ve got is data error message (although row was deleted successfully). I tried this:

Companies.CompaniesList.RemoveAt(dataGridView1.SelectedRows[0].Index);
bs = new BindingSource();
bs.DataSource = Companies.CompaniesList;
dataGridView1.DataSource = bs;

It works as expected. The question is: why?

  • 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-13T08:28:42+00:00Added an answer on May 13, 2026 at 8:28 am

    It is common for property changes (via set) to detect and ignore changes that do nothing, so in the line:

    dataGridView1.DataSource = Companies.CompaniesList;
    

    I expect that DataSource is already Companies.CompaniesList, so nothing happened. No code executed except to test the reference. Checking in reflector confirms this (DataGridView.DataSource):

    set
    {
        if (value != this.DataSource)
        {
            ...
        }
    }
    

    So it only does anything when the reference is updated.

    Additionally, since List<T> doesn’t implement the necessary binding interfaces, the grid has no idea that the list contents have been changed, hence the error. Now contrast:

    bs = new BindingSource();
    bs.DataSource = Companies.CompaniesList;
    dataGridView1.DataSource = bs;
    

    Here, the DataSource has changed, as bs is an entirely new object. This causes the entire grid to rebind.

    Another option is to use BindingList<T>, or to remove from the BindingSource (rather than the List<T>) which should operate in both directions.

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

Sidebar

Related Questions

Tried almost everything and got no success making DefaultHttpClient() to work with expired SSL
I would like to bind a list box to an observable collection in code
Basically I'm using the ItemSource property of the datagrid to bind a generic list
I'm trying to bind a combobox to a list of items (ObservableCollection) on my
I'm trying to bind some indexes and they're corresponding strings so I tried using
this appears to bind, but rows in Details Grid are empty. Something is off/missing?
I have a DataGridView to which I've set a list of objects to the
I want to put temporary datas into a generic list and bind it to
I'm trying to bind anchor attributes to a KnockoutJS ViewModel field. I tried something
I have a ListView in a Windows Form that I bind a list of

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.