Click here to Skip to main content
15,946,525 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to programmatically add a row to DataGridView (a datasource was
binded with it), but when I call the method DataGridView.Rows.Add, a
System.InvalidOperationException will be thrown and the error message is:
Rows cannot be programmatically added to the DataGridView's rows
collection when the control is data-bound.

private void add_click(object sender, EventArgs e)
    DataRow row = db1.NewRow();
 catch (Exception exceptionObj)


What code change should be done to dynamically add a row to datagrid when it is bound to data source.?
Updated 4-Oct-11 20:12pm

1 solution

You need to add the new row to the DataSource instead of the DataGridView.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900