我有一个包含 Dataset ds 和 DataGridView dgv 的 WinForms 应用程序。 dgv 绑定(bind)到 ds。
ds 通过 Task() 更新,该 Task() 使用 TableAdapter.Fill() 方法定期查询数据库。我在这里遇到了两个问题。
拥有可由用户编辑并通过更改绑定(bind)数据集(在另一个线程中更新)来更新 DataGridView 的最佳方法是什么?
最佳答案
对于您的第 2 点,您可以使用函数 Invoke
从控制类。该函数将在 UI 线程中执行该函数。
http://msdn.microsoft.com/en-us/library/zyzhdc6b.aspx
前任。 :
// Invoke an anonymous method on the thread of the form.
this.Invoke((MethodInvoker) delegate
{
//Call your function to update your datagridview with the dataset in parameters
...
});
关于c# - DataGridView 可编辑时 DataGridView/数据集的线程安全更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5301714/