当我运行这段代码
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添加一行