Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.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#数据表单元格更新问题_C#_Datagridview_Bindingsource - Fatal编程技术网

c#数据表单元格更新问题

c#数据表单元格更新问题,c#,datagridview,bindingsource,C#,Datagridview,Bindingsource,在数据表的单元格中输入数据时出错。 错误代码:StackTrace: 在System.Windows.Forms.BindingSource.get_Count()中 位于System.Windows.Forms.DataGridViewCell.SetValue(Int32行索引,对象值) 电话:1633行 在System.Threading.Tasks.Task.Execute()中 第1633行:TableGridview1.Rows[i]。Cells[21]。Value=teknikr

在数据表的单元格中输入数据时出错。 错误代码:
StackTrace:
在System.Windows.Forms.BindingSource.get_Count()中
位于System.Windows.Forms.DataGridViewCell.SetValue(Int32行索引,对象值)
电话:1633行
在System.Threading.Tasks.Task.Execute()中

第1633行:TableGridview1.Rows[i]。Cells[21]。Value=teknikresimim

我应该在每次更新单元格后再次绑定吗

for (int i = 0; i < TableGridview1.Rows.Count; i++)
                {
                    #region kolon_adi tanimla
                    string parcano_kolon = Convert.ToString(TableGridview1.Rows[i].Cells[1].Value);
                    string rev_kolon = Convert.ToString(TableGridview1.Rows[i].Cells[2].Value);
                    string op1_kolon = Convert.ToString(TableGridview1.Rows[i].Cells[13].Value);
                    string dwgyolu_kolon = Convert.ToString(TableGridview1.Rows[i].Cells[23].Value);
                    string pdfyolu_kolon = Convert.ToString(TableGridview1.Rows[i].Cells[24].Value);
                    string dizinler = Convert.ToString(TableGridview1.Rows[i].Cells[25].Value);
                    string sirano = Convert.ToString(TableGridview1.Rows[i].Cells[38].Value);
                    #endregion
                    string pdfim = null;
                    string teknikresimim = null;
                    string dwg_kontrol = null;
                        var taskList = new List<Task>
                        {
                            Task.Factory.StartNew(() =>
                            {
                                pdfim = PDFdir(parcano_kolon, dizinler, rev_kolon, sirano);
                                TableGridview1.Rows[i].Cells[22].Value = pdfim;
                                TableGridview1.UpdateCellValue(22, i);
                            }),
                            Task.Factory.StartNew(() =>
                            {
                                teknikresimim = TeknikDir(parcano_kolon, dizinler)[0];
                                TableGridview1.Rows[i].Cells[21].Value = teknikresimim;
                                TableGridview1.UpdateCellValue(21, i);
                            }),
                            Task.Factory.StartNew(() =>
                            {
                                dwg_kontrol = DwgBul(parcano_kolon, rev_kolon, op1_kolon, sirano)[0];
                                TableGridview1.Rows[i].Cells[20].Value = dwg_kontrol;
                                TableGridview1.UpdateCellValue(20, i);
                            })
                        };
                        Task.WaitAll(taskList.ToArray());
                }
for(int i=0;i
{
pdfim=PDFdir(帕卡诺科隆、迪兹勒、科隆、西拉诺);
TableGridview1.Rows[i].Cells[22].Value=pdfim;
TableGridview1.UpdateCellValue(22,i);
}),
Task.Factory.StartNew(()=>
{
teknikresimim=TeknikDir(parcano_kolon,dizinler)[0];
TableGridview1.行[i].单元格[21].值=teknikresimim;
TableGridview1.UpdateCellValue(21,i);
}),
Task.Factory.StartNew(()=>
{
dwg_kontrol=DwgBul(帕卡诺科隆,版次科隆,op1_科隆,西拉诺)[0];
TableGridview1.Rows[i].Cells[20].Value=dwg\u kontrol;
TableGridview1.UpdateCellValue(20,i);
})
};
Task.WaitAll(taskList.ToArray());
}

您正在尝试从其他线程更新UI。 您需要以代码隐藏的形式创建一个方法来更新datagridview,然后使用调用从任务中调用它:


UpdateMethodName?.Invoke(…)

您不能从后台线程更新GUI元素(或扩展数据绑定数据)。这个错误是故意的。什么错误?你能发布完整的错误消息吗?@Zer0我试过了。但是给了我同样的issue@Sinatr; System.InvalidOperationException HResult=0x80131509İleti=veri kaynağolamaz中的BindingSource Kendisin。数据源ve DataMemberözelliklerini BindingSource'a geri başvuran değerre ayarlamayın。Kaynak=System.Windows.Forms StackTrace:at System.Windows.Forms.BindingSource.get_Count()at System.Windows.Forms.DataGridViewCell.SetValue(Int32 rowIndex,对象值)at GetBOMList.GetBOMListx.c_DisplayClass59_1.b_3()at GetBOMList.cs:System.Threading.Tasks.Task.Execute()的第1633行