usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;usingSystem.Threading;namespacewindowsformsapp3{ Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); } Public voidButton1_Click (Objectsender, EventArgs e) { //var mylist =new list<int> (); //datagridview1.rowcount = 1; //Datagridview1.datasource = mylist; //MyList. ADD (10); //DataRow data = Datatable.newrow (); //MyList. ADD (20); //MyList. ADD (30); //datatable.rows[0][0] = 0; //Datagridview1.rows[0]. Cells[0]. Value =data[0]; //Datagridview1.rows[1]. Cells[0]. Value = mylist[1]; //datagridview1.rows[2]. Cells[0]. Value = mylist[2]; //MyList. Remove (0); //Datagridview1.datasource = mylist; //MessageBox.Show (convert.tostring (mylist[0));DataTable datatable =NewDataTable (); DATATABLE.ROWS.ADD (); DATATABLE.COLUMNS.ADD ("1"); datatable.rows[0][0] ="Hello"; Datagridview1.datasource=dataTable; } Private voidButton3_Click (Objectsender, EventArgs e) { }
Through the above experiments can be found that when the Datagriview binding list can not be refreshed in real time, and the DataTable can be implemented in real-time refresh.
C # DataGridView Binding list and DataTable