Weeman Osekre

Weeman Osekre

  • NA
  • 56
  • 3.5k

Datagridview controls

Nov 17 2020 10:58 AM
I have a form with two gridview one displays the results from a search .textbox and the other displays a selected row from the first grid view . Then the rows in the second gridview is saved into a database call unpaid checks. private void btnadd_Click(object sender, EventArgs e) { for (int i = dataGridView1.RowCount - 1; i <= 0; i++) { DataGridViewRow row = dataGridView1.Rows[i]; if (Convert.ToBoolean(row.Cells["selectrow"].Value = true)) { Formq pan = new Formq(); pan.ShowDialog(); string may = Formq.mark1; productBindingSource4.AddNew(); dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells[1].Value = dataGridView1.Rows[i].Cells[1].Value.ToString(); dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells[2].Value = dataGridView1.Rows[i].Cells[2].Value.ToString(); dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells[3].Value = dataGridView1.Rows[i].Cells[3].Value.ToString(); dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells[4].Value = dataGridView1.Rows[i].Cells[4].Value.ToString(); dataGridView2.Rows[dataGridView2.Rows.Count-1].Cells["quantity"].Value = may; int qu = Int32.Parse(dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells["quantity"].Value.ToString()); string pp = dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells[3].Value.ToString(); Double rpp = Double.Parse(pp); Decimal rrpp = (decimal)rpp; Decimal tp = rrpp * qu; dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells["tprice"].Value = tp + ".00"; Double sum = 0; for (int f = 0; f < dataGridView2.Rows.Count; f++) { sum += double.Parse(dataGridView2.Rows[f].Cells[6].Value.ToString()); } string msun = (sum.ToString()); libt2.Text = msun; Then it’s form is closed and a dynamic button is created. When I want to update the data in the unpaidchecks . I use this private void btn_Click(object sender, EventArgs e) { this.Hide(); salesitems op = new salesitems(); op.Show(); int i = 0; Button btn = sender as Button; string btntext = btn.Text; kk.getunpaid(int.Parse(btn.Text)); op.dataGridView2.DataSource = kk.getunpaid(int.Parse(btn.Text)); foreach (var dy in kk.getunpaid(int.Parse(btn.Text))) { op.dataGridView2.Rows[i].Cells["quantity"].Value = dy.quantity.ToString(); op.dataGridView2.Rows[i].Cells["Tprice"].Value = dy.tprice.ToString(); i++; op.libtabsno.Text = dy.tabel_sno_.ToString(); op.libuser.Text = dy.user.ToString(); op.libtno.Text = dy.tabel_no_.ToString(); op.libt2.Text = dy.total.ToString() But the problem is , it doesn’t add a new row. This code dose not work when the productBindingSource4.AddNew(); The dynamic button is clicked I need help

Answers (1)