WinForm programs use the list object to bind DataGridView data sources

Source: Internet
Author: User

     1, when the List<t> object is bound to the DataGridView data Source property, the content of the data source is not updated dynamically, and if the data in the List<t> object collection changes, the data source of the control will not be updated.
It is generally not recommended to use list<t> to populate the data source of the data display control.
     If you must use the List<t> object to bind the data source, first set the DataGridView DataSource property to New List<t> (), and then list<t> The collection is re-assigned to the DataSource property. This resolves both the synchronization update issue.
When the DataGridView datasource is bound to a DataTable, when the contents of the DataTable change, the contents of DataGridView automatically follow the DataTable without rebinding the data source ; (Note: You cannot set the DataSource property of DataGridView to NULL, otherwise the column structure already set in DataGridView is broken.)     2, data binding after the addition of the deletion problem: If you want to bind in the DataGridView in the list<t> to add the deletion of data, the first to convert list<t> to Bindinglist<t> Bind again: Datagridview1.datasource=new bindinglist<myclass> (New list<myclass> ()). Otherwise, there will be many unexpected mistakes. such as: After the initial binding of the empty data after the addition of data binding, but the Datagridview.currentcell property is not taken.

list<urllistobject> rltlist = new list<urllistobject> (); rltlist = this. Analysishtml ();d atagridview1.datasource = new bindinglist<urllistobject> (rltlist);//Modify the data and refresh the            foreach ( Urllistobject per_o in Rltlist)            {                Per_o.finalurl = Baseobjects.gettheredirecturl (Per_o.url);                            }            This.dataGridView1.Refresh ();

  

WinForm programs use the list object to bind DataGridView data sources

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.