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

时间:2020-06-29 22:04:51

标签: c# sql datagridview

当我运行这段代码

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

0 个答案:

没有答案