![](/img/trans.png)
[英]Adding multiple row from one datagridview to datagridview c# windows form
[英]adding multiple items one by one in datagridview in c# window form
private void btnSave1_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow dgvr in ProductAddGridView.Rows)
{
dgvr.Cells[0].Value = productIDTextBox.Text;
dgvr.Cells[1].Value = productTypeIDComboBox.Text;
dgvr.Cells[2].Value = companyIDComboBox.Text;
dgvr.Cells[3].Value = productPurchaseRateTextBox.Text;
dgvr.Cells[4].Value = productQtyTextBox.Text;
dgvr.Cells[5].Value = productDescriptionRichTextBox.Text;
dgvr.Cells[6].Value = Convert.ToString(Convert.ToUInt32(productQtyTextBox.Text.Trim()) * Convert.ToDecimal(productPurchaseRateTextBox.Text));
}
}
我正在尝试在datagridview中一个接一个地添加多个产品,然后再将其保存到数据库中。 但是每当我第二次在datagridview中添加一行时,第一行就会被第二行替换-它仅适用于单行添加。
我并没有完全得到您想要的东西,但是如果您想在datagrid视图中添加多行,则需要创建一个数据行,然后可以将该行添加到datagrid中。 您可以参考此链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.