![](/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.