为什么在尝试添加新行时会出现此错误?

ki0zmccv  于 2021-08-01  发布在  Java
关注(0)|答案(0)|浏览(248)

当我运行这个代码时

else
{
    if (dataGridView1.Rows[e.RowIndex].Cells[14].Value.ToString() != "Não")
    {
        if (dataGridView2.ColumnCount >= 1)
        {
            foreach (DataGridViewRow row in dataGridView2.Rows)
            {
                if (row.Cells["Id_Veiculo"].Value == null)
                {
                    dataGridView2.Rows.Add(N_Vender, dataGridView1.Rows[e.RowIndex].Cells[0].Value, nomeC);

                    int a;

                    a = Convert.ToInt32(bunifuCustomTextbox3.Text);
                    string s = dataGridView1.Rows[e.RowIndex].Cells[17].Value.ToString();
                    int b = int.Parse(s);

                    (bunifuCustomTextbox3.Text) = Convert.ToString(a + b);
                    break;
                }
                else if (Id_Veiculo == (int)row.Cells["Id_Veiculo"].Value)
                {
                    //dataGridView2.Rows[row.Index].Cells[14].Value = (int)(dataGridView2.Rows[row.Index].Cells[1].Value) + 1;

                    int a;
                    a = Convert.ToInt32(bunifuCustomTextbox3.Text);

                    string s = dataGridView1.Rows[e.RowIndex].Cells[17].Value.ToString();

                    int b = int.Parse(s);

                    (bunifuCustomTextbox3.Text) = Convert.ToString(a + b);
                    break;
                }
            }
        }

        dataGridView1.Rows[e.RowIndex].Cells[14].Value = "Não";
    }
}

当我按datagridview1中的一行时,支持在中创建新行 datagridview2 有一些关于 datagridview1 . 但屏幕上出现了一个错误 dataGridView2.Rows.Add ,我不知道该怎么办。
我正在尝试向datagridview2添加一行
https://gyazo.com/eaeb5a163b61bb1bef128a726712d2c6

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题