Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在DataGridView中使用ProgressBar控件_C#_Winforms_Datagridview_Progress Bar - Fatal编程技术网

C# 如何在DataGridView中使用ProgressBar控件

C# 如何在DataGridView中使用ProgressBar控件,c#,winforms,datagridview,progress-bar,C#,Winforms,Datagridview,Progress Bar,当我的DataGridView加载数据时,我想在C中使用ProgressBar控件,但当我运行程序时,我得到一个错误: 跨线程操作无效:控件“dataGridView1”是从创建它的线程以外的线程访问的 dataGridView1.BeginInvoke((MethodInvoker)delegate { this.dataGridView1.DataSource = dt; }); 代码: 在创建dataGridView1基础句柄的线程上异步执行指定的委托 dataGridView1

当我的DataGridView加载数据时,我想在C中使用ProgressBar控件,但当我运行程序时,我得到一个错误:

跨线程操作无效:控件“dataGridView1”是从创建它的线程以外的线程访问的

dataGridView1.BeginInvoke((MethodInvoker)delegate
{
    this.dataGridView1.DataSource = dt;
});
代码:


在创建dataGridView1基础句柄的线程上异步执行指定的委托

dataGridView1.BeginInvoke((MethodInvoker)delegate
{
    this.dataGridView1.DataSource = dt;
});
因为progressbar只是一个选框显示。在运行后台工作程序之前,只需将其放到前台即可

progressBar1.BringToFront();
progressBar1.Show();
_bw.RunWorkerAsync();

使用BeginInvoke或dataGridView1.Invoke for dataGridView1是否可以使用Invoke对象验证我的代码?是否尝试给出答案?在后台工作程序上查找演练;请特别注意reportprogress函数!