为什么不根据与绑定源连接的数据集更新数据网格视图?
Why a data grid view is not being updated based on data set connected with bindig source?
我有一个 dataGridView
控件,数据源设置在 dataTableDocumentsBindingSource
当我使用以下代码更新 dataSet1
时,dataGridView
未更新:
DataSet1 ds = new DataSet1();
/.../
DataTable documentsTable = ds.Tables["DataTableDocuments"];
DataRow workRow = documentsTable.NewRow();
workRow["id"] = Int32.Parse(item.SelectSingleNode("id").InnerText);
workRow["Title"] = item.SelectSingleNode("title").InnerText;
documentsTable.Rows.Add(workRow);
/.../
return ds;
如何在相应的数据集更新时让dataGridView更新?
我已经尝试了 dataGridView.Refresh()
和 dataGridView.Update()
,但都不起作用。
如果你能这样做的话
public class Xyz
{
DataSet1 ds = new DataSet1();
/.../
private void UpdateData()
{
DataTable documentsTable = ds.Tables["DataTableDocuments"];
DataRow workRow = documentsTable.NewRow();
workRow["id"] = Int32.Parse(item.SelectSingleNode("id").InnerText);
workRow["Title"] = item.SelectSingleNode("title").InnerText;
documentsTable.Rows.Add(workRow);
yourbindingsource.ResetBindings(false);
}
}
我有一个 dataGridView
控件,数据源设置在 dataTableDocumentsBindingSource
当我使用以下代码更新 dataSet1
时,dataGridView
未更新:
DataSet1 ds = new DataSet1();
/.../
DataTable documentsTable = ds.Tables["DataTableDocuments"];
DataRow workRow = documentsTable.NewRow();
workRow["id"] = Int32.Parse(item.SelectSingleNode("id").InnerText);
workRow["Title"] = item.SelectSingleNode("title").InnerText;
documentsTable.Rows.Add(workRow);
/.../
return ds;
如何在相应的数据集更新时让dataGridView更新?
我已经尝试了 dataGridView.Refresh()
和 dataGridView.Update()
,但都不起作用。
如果你能这样做的话
public class Xyz
{
DataSet1 ds = new DataSet1();
/.../
private void UpdateData()
{
DataTable documentsTable = ds.Tables["DataTableDocuments"];
DataRow workRow = documentsTable.NewRow();
workRow["id"] = Int32.Parse(item.SelectSingleNode("id").InnerText);
workRow["Title"] = item.SelectSingleNode("title").InnerText;
documentsTable.Rows.Add(workRow);
yourbindingsource.ResetBindings(false);
}
}