标签:text lin row system eric send end c# int
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; namespace WindowsFormsApp3 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public void button1_Click(object sender, 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 = new DataTable(); dataTable.Rows.Add(); dataTable.Columns.Add("1"); dataTable.Rows[0][0] ="你好"; dataGridView1.DataSource = dataTable; } private void button3_Click(object sender, EventArgs e) { }
通过以上实验可以发现,当datagriview 绑定 list的时候 不可以实时刷新,而datatable就可以实现实时刷新。
C# dataGridView绑定List与datatable
标签:text lin row system eric send end c# int
原文地址:https://www.cnblogs.com/snow-zhang/p/9164534.html