我在 C# .net 4 中使用 datagridview 来开发我的应用程序。有时在我的应用程序启动时,我的 datagridview 没有完全处理,它使应用程序崩溃或者我必须重新启动应用程序。
摆脱它所需的建议。我使用“for”循环在数据网格内创建数据网格的列和行。这可能是延迟处理的原因之一......
private void Create_Datatables()
{
//////////////////// Create data tables, row and Columns in the Datagrids ////////////////////////////////
DataTable[] Panel_tables = new DataTable[28];
for (int i = 0; i <= 27; i++)
{
Panel_tables[i] = new DataTable();
}
int length_col = 16;
for (int i = 1; i <= length_col; i++)
{
Panel_tables[0].Columns.Add(i.ToString());
}
int length_row = 2;
for (int i = 1; i <= length_row; i++)
{
Panel_tables[0].Rows.Add("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");
}
int dg_main = 23;
for (int i = 0; i < dg_main; i++)
{
Panel_tables[i + 1] = Panel_tables[i].Copy();
}
dataGridView1.DataSource = Panel_tables[0];
dataGridView2.DataSource = Panel_tables[1];
dataGridView3.DataSource = Panel_tables[2];
dataGridView4.DataSource = Panel_tables[3];
dataGridView5.DataSource = Panel_tables[4];
dataGridView6.DataSource = Panel_tables[5];
dataGridView7.DataSource = Panel_tables[6];
dataGridView8.DataSource = Panel_tables[7];
dataGridView9.DataSource = Panel_tables[8];
dataGridView10.DataSource = Panel_tables[9];
dataGridView11.DataSource = Panel_tables[10];
dataGridView12.DataSource = Panel_tables[11];
dataGridView13.DataSource = Panel_tables[12];
dataGridView14.DataSource = Panel_tables[13];
dataGridView15.DataSource = Panel_tables[14];
dataGridView16.DataSource = Panel_tables[15];
dataGridView17.DataSource = Panel_tables[16];
dataGridView18.DataSource = Panel_tables[17];
dataGridView19.DataSource = Panel_tables[18];
dataGridView20.DataSource = Panel_tables[19];
dataGridView21.DataSource = Panel_tables[20];
dataGridView22.DataSource = Panel_tables[21];
dataGridView23.DataSource = Panel_tables[22];
dataGridView24.DataSource = Panel_tables[23];
for (int i = 0; i < length_col; i++)
{
Panel_tables[24].Columns.Add(i.ToString());
}
length_row = 3;
for (int i = 0; i < length_row; i++)
{
Panel_tables[24].Rows.Add("", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");
}
int dg_xio = 27;
for (int i = 24; i < dg_xio; i++)
{
Panel_tables[i + 1] = Panel_tables[i].Copy();
}
dataGridView25.DataSource = Panel_tables[24];
dataGridView26.DataSource = Panel_tables[25];
dataGridView27.DataSource = Panel_tables[26];
dataGridView28.DataSource = Panel_tables[27];
}