我需要从datagridview取消绑定数据源以便以编程方式添加行,但是在取消绑定后,我无法将数据保留在datagridview中。任何解决方案这是代码:
try
{
XmlReader xmlFile = XmlReader.Create(AppDomain.CurrentDomain.BaseDirectory + "data.xml", new XmlReaderSettings());
ds.ReadXml(xmlFile);
dataGridView1.Columns.Clear();
dataGridView1.Rows.Clear();
dataGridView1.Refresh();
dataGridView1.DataSource = ds.Tables[0].DefaultView;
// dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = null;
// dataGridView1.AutoResizeColumns();
}
catch (Exception ex)
{
MessageBox.Show("Eroor! "+ ex);
}