Weeman Osekre

Weeman Osekre

  • NA
  • 56
  • 3.5k

How to show two data source in one gridview

Dec 16 2020 12:19 AM
I am working on a POS. System with winforms . To create a items list for a guest I selected the select the selected items from a table in my database( products) then display them a gridview with it corresponding info. So the the guest table which was just created is not paid it’s then saved into another table in my database ( unpaidchecks) . When a user login to the application and there are unpaidchecks under the user’s name a dynamic button is created to show all the unpaidchecks in ascending order . Then I created a click event for the dynamic button. When it’s clicked it show the data of that particular unpaidcheck. But when I want to update it, as in add new items from product, a new row is not added for the new item to be displayed. The gridview is bounded to productbindingsource at design time and when the dynamic button is clicked the gridview is bounded to ( unpaidchecks). I need help on how to navigate this . I use this to open a table when a guest places an order. 
  1. private void btnadd_Click(object sender, EventArgs e) {  
  2.   for (int i = dataGridView1.RowCount - 1; i <= 0; i++) {  
  3.     DataGridViewRow row = dataGridView1.Rows[i];  
  4.     if (Convert.ToBoolean(row.Cells["selectrow"].Value = true)) {  
  5.       Formq pan = new Formq();  
  6.       pan.ShowDialog();  
  7.       string may = Formq.mark1;  
  8.       productBindingSource4.AddNew();  
  9.       dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells[1].Value = dataGridView1.Rows[i].Cells[1].Value.ToString();  
  10.       dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells[2].Value = dataGridView1.Rows[i].Cells[2].Value.ToString();  
  11.       dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells[3].Value = dataGridView1.Rows[i].Cells[3].Value.ToString();  
  12.       dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells[4].Value = dataGridView1.Rows[i].Cells[4].Value.ToString();  
  13.       dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells["quantity"].Value = may;  
  14.       int qu = Int32.Parse(dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells["quantity"].Value.ToString());  
  15.       string pp = dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells[3].Value.ToString();  
  16.       Double rpp = Double.Parse(pp);  
  17.       Decimal rrpp = (decimal) rpp;  
  18.       Decimal tp = rrpp * qu;  
  19.       dataGridView2.Rows[dataGridView2.Rows.Count - 1].Cells["tprice"].Value = tp + ".00";  
  20.       Double sum = 0;  
  21.       for (int f = 0; f < dataGridView2.Rows.Count; f++) {  
  22.         sum += double.Parse(dataGridView2.Rows[f].Cells[6].Value.ToString());  
  23.       }  
  24.       string msun = (sum.ToString());  
  25.       libt2.Text = msun;  
And this when the dynamic button is clicked.
  1. private void btn_Click(object sender, EventArgs e) {  
  2.   this.Hide();  
  3.   salesitems op = new salesitems();  
  4.   op.Show();  
  5.   int i = 0;  
  6.   Button btn = sender as Button;  
  7.   string btntext = btn.Text;  
  8.   kk.getunpaid(int.Parse(btn.Text));  
  9.   op.dataGridView2.DataSource = kk.getunpaid(int.Parse(btn.Text));  
  10.   foreach(var dy in kk.getunpaid(int.Parse(btn.Text))) {  
  11.     op.dataGridView2.Rows[i].Cells["quantity"].Value = dy.quantity.ToString();  
  12.     op.dataGridView2.Rows[i].Cells["Tprice"].Value = dy.tprice.ToString();  
  13.     i++;  
  14.     op.libtabsno.Text = dy.tabel_sno_.ToString();  
  15.     op.libuser.Text = dy.user.ToString();  
  16.     op.libtno.Text = dy.tabel_no_.ToString();  
  17.     op.libt2.Text = dy.total.ToString() 

Answers (1)