I have populated a DataGridView from an XML file via loading to a DataSet. However, after I load the data I can no longer insert rows at run-time as I get this error:
"Rows cannot be programmatically added to the datagridview's row collection when the control is data-bound"
private void LoadBtn_Click(object sender, EventArgs e)
{
DTable.Clear();
DTable.Reset();
var ds = new DataSet();
ds.ReadXml(@"C:\setup.xml", XmlReadMode.ReadSchema);
foreach (DataGridViewColumn col in dataGridView1.Columns)
{
DTable.Columns.Add(col.Name);
col.DataPropertyName = col.Name;
}
//dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = ds.Tables["TableName"];
}
I understand the concept of the problem I think. If my XML file only contains 7 rows and is the source of the DataGridView, then it is bound to 7 rows and more cannot be added, but I would like the user to be able to dynamically change this and then re-save the XML. I am OK with knowing how to re-save, just not how to "unlock" the row problem.
Many Thanks, Tom