[Reprinted] The DataGridView uses a collection as the data source and synchronously updates it.

Source: Internet
Author: User

[Reprinted] The DataGridView uses a collection as the data source and synchronously updates it.

Address: http://hi.baidu.com/netyro/item/7340640e36738a813c42e239

When I was working on a project today, I encountered a problem of scratching my head. When the data source of the DataGridView is a generic set, the displayed content of the DataGridView cannot be updated synchronously after the set content changes, and I have been searching for N times online, no solution was found. By mistake, we found a generic collection BindingList that supports data binding. This collection perfectly solves the problem of updating the content of a general generic set, the disadvantages of the contents of the DataGridView cannot be updated.

The details are as follows:

There are two dview controls in the interface. When you click a row record in the DataGridView, the record is added to the following DataGridView, at the beginning, both dview use a generic set List <> as the data source. When you click a row in the top DataGridView, the corresponding entity of the row is saved to the data source set of the lower dview, but the lower DataGridView can always display only one record. There are two numbers in the dialog box in the middle of the interface, the first one is "1", which means that only one row of records are in the current DataGridView, and the second one is "2", which refers to the number of entities in the data source set of the DataGridView below, that is to say, there are two records in the set, but only the records added when you click DataGridView for the first time are displayed in the DataGridView.

After changing the data source of the DataGridView to BindingList <>

Added successfully !!!

There are many ways to use BindingSource, such as using BindingSource. In fact, the simplest way is to use BindingList, a generic set that supports data binding. <>, change the data source of the DataGridView to BindingList <>.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.