【发布时间】:2020-04-08 07:23:52
【问题描述】:
在数据表的单元格中输入数据时出现错误。
错误代码:StackTrace:
at System.Windows.Forms.BindingSource.get_Count()
at System.Windows.Forms.DataGridViewCell.SetValue(Int32 rowIndex, Object value)
at :line 1633
at 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());
}
【问题讨论】:
-
您不能从后台线程更新 GUI 元素(或扩展的数据绑定数据)。此错误是设计使然。
-
什么错误?你能发布一个完整的错误信息吗?
-
@Zer0 我试过了。但给出了同样的问题
-
@Sinatr; System.InvalidOperationException HResult=0x80131509 İleti=BindingSource kendisinin veri kaynağı olamaz。 DataSource ve DataMember özelliklerini BindingSource'a geri başvuran değerlere ayarlamayın。 Kaynak=System.Windows.Forms StackTrace:在 System.Windows.Forms.BindingSource.get_Count() 在 System.Windows.Forms.DataGridViewCell.SetValue(Int32 rowIndex, Object value) 在 GetBOMList.GetBOMListx.c__DisplayClass59_1.
GetBOMList.cs 中的 b__3():System.Threading.Tasks.Task.Execute() 的第 1633 行
标签: c# datagridview bindingsource