I get an error when entering data into the cell in the data table.
Error code: 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()
Line 1633: TableGridview1.Rows[i].Cells[21].Value = teknikresimim;
Should I bind again after every update cells?
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());
}
You are trying to update UI from a different thread. You need to create a method in the Form code behind to update your datagridview then call it from your Task using an invoke:
UpdateMethodName?.Invoke(…)