After DataGridView bind the data source to add rows

 

This link: https://blog.csdn.net/u012386475/article/details/88639799

When the data source is already bound, not in a manner Add to add the line, will complain

Solution one:

DataRow dr =((DataTable)dataGridView1.DataSource).NewRow;

((DataTable)dataGridView1.DataSource).Rows.Add(dr);

 

Solution two:

// First datatable (dt) new line, and then re-bind the data source

//DataTable dt =new DataTable();

DataRow dr=dt.NewRow();

dt.Rows.Add(dr);

dataGridView1.DataSource=dt;

 

Guess you like

Origin www.cnblogs.com/wfy680/p/12004515.html