我有一个绑定到表格的DataGridView。在与DataGridView相同的表单上,我有几个文本框和一个按钮,用于向数据库添加新值,并希望它们也显示在GridView中。保存到数据库中是有效的,只是新值未显示在GridView中。我尝试了以下方法:
this.Validate();
this.pBindingSource.EndEdit();
this.pTableAdapter.Update(this.DBDataSet);
pDataGridView.Refresh();
这个方法不起作用。据我所知,.Refresh 方法只会重新绘制 GridView,所以在更新 tableAdapter 后应该会生效,但实际上并没有。
然后我尝试了:
this.pDataGridView.DataSource = null;
this.pDataGridView.DataSource = this.pBindingSource;
pDataGridView.Refresh();
这也不起作用。然后尝试对绑定源进行ResetBindings(),但它也无法正常工作,然后我就没有了更多的想法。
如何刷新DataGridView?