[英]Cannot add rows to my data-bound dataGridview dynamically
RDP0 yeni = new RDP0();
yeni.IPADDRESS = "1.1.1.1";
yeni.PASSWORD = " 10akh0";
yeni.NO = 8;
yeni.CUSTID = 1000;
testList.Add(yeni);
dataGridView1.DataSource = testList;
I'm getting data-bound error therefore I cannot add rows. 我收到数据绑定错误,因此无法添加行。 Any help would be great. 任何帮助都会很棒。 This is how I bound data to my dataGV: 这是我将数据绑定到dataGV的方式:
tm = new testModel();
var query = from fe in tm.ERDP0 select fe;
testList = query.ToList();
dataGridView1.DataSource = testList;
If the DataGridView
is data bound you cannot add new rows/columns to the DataGridView
directly. 如果DataGridView
是数据绑定的,则不能直接向DataGridView
添加新的行/列。 But you could add a row to a DataTable
which will update your DataGridView
automatically. 但是您可以在DataTable
添加一行,这将自动更新DataGridView
。
DataTable dt = dataGridView1.DataSource as DataTable;
dt.Rows.Add("new row");
Or you could add the new row to your source list and then reset the DataSource: 或者,您可以将新行添加到源列表中,然后重置DataSource:
testList.Add(youritem);
dataGridView1.DataSource = null;
dataGridView1.DataSource = testList;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.