I have datagridview that contains information from my database. But I need to add new rows with a button.
This error message appears:
Rows cannot be programmatically added to the datagridview's row collection when the control is data-bound
private void pictureBox1_Click(object sender, EventArgs e)
{
int rowId = dgvArticulos.Rows.Add(new DataGridViewRow());
}
I read many posts but they're using DataTable and it doesnt work for my case. Does anybody knows how to solve this issue?
Thanks in advance
I solve my problem. I created a new List and set the value of my DataSource. After that, I was able to add a row to the new list. It works perfect
List<Documento_Articulo> listaDA = lista;
listaDA.Add(new Documento_Articulo());
dgvArticulos.DataSource = null;
dgvArticulos.DataSource = listaDA;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.