[英]C# add selected row from one DatagridView to another and with second select add + quantity
I have two DatagridViews in Windowsform c#, in one I have selected all my products(Dgtv_artikelbestellung) from Database and dipslayed there.我在 Windowsform c# 中有两个 DatagridViews,其中一个我从数据库中选择了我所有的产品(Dgtv_artikelbestellung)并在那里放置。
the other one is for ordered product (dgv_bestellteArtikel, I want if I click one the sign "+" it adds that selected row to the other DataGridView and if I double click on the same selected row it should then in the 2nd Datagridview ++1 in columns "Menge"Quantity. So far I can add the rows but that if I second time add the same product it doesn't add quantity. How can I achive that? Can someome please help? here how it looks like: Datagridview demo And here the code I have for it.另一个用于订购产品(dgv_bestellteArtikel,如果我单击一个符号“+”,我想要它会将选定的行添加到另一个 DataGridView,如果我双击同一选定的行,它应该在第二个 DataGridview ++1在“Menge”列中。到目前为止,我可以添加行,但是如果我第二次添加相同的产品,它不会添加数量。我怎样才能做到这一点?有人可以帮忙吗?这里看起来像: Datagridview demo这里是我的代码。
private void Dgtv_artikelbestellung_CellClick(object sender, DataGridViewCellEventArgs e)
{
string tttts = "";
bool gefunden = false;
if (Dgtv_artikelbestellung.Rows.Count > 0 && Dgtv_artikelbestellung.SelectedRows.Count > 0)
{
for (int i = 0; i < Dgtv_artikelbestellung.SelectedRows.Count; i++)
{
int indexvar = dgv_bestellteArtikel.Rows.Add();
dgv_bestellteArtikel.Rows[indexvar].Cells[0].Value = Dgtv_artikelbestellung.SelectedRows[i].Cells[0].Value.ToString();
dgv_bestellteArtikel.Rows[indexvar].Cells[1].Value = Dgtv_artikelbestellung.SelectedRows[i].Cells[1].Value.ToString();
dgv_bestellteArtikel.Rows[indexvar].Cells["Menge"].Value = Convert.ToInt32(dgv_bestellteArtikel.Rows[indexvar].Cells["Menge"].Value) + 1;
tttts=dgv_bestellteArtikel.Rows[indexvar].Cells["Menge"].Value.ToString();
if(tttts != null && tttts.ToString()== tttts)
{
gefunden = true;
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.