kwangu

Adding selected rows from one datagridview to another

Oct 5th, 2017
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.51 KB | None | 0 0
  1. Dim pcode As String = ""
  2.         Dim pID As Integer
  3.         Dim pname As String = ""
  4.         Dim desc As String = ""
  5.         Dim uom As String = ""
  6.         Dim price As Decimal
  7.         Dim total As Decimal
  8.         With pForm.QformEdit.dgvData
  9.             Dim i As Integer
  10.             Dim counter As Integer = 0
  11.             For Each row As DataGridViewRow In dgvInventory.Rows
  12.                 pID = row.Cells("productID").Value
  13.                 pcode = row.Cells("productCode").Value.ToString()
  14.                 pname = row.Cells("productName").Value.ToString()
  15.                 desc = row.Cells("description").Value.ToString()
  16.                 uom = row.Cells("uom").Value.ToString()
  17.                 price = row.Cells("SellingPrice").Value.ToString()
  18.                 total = row.Cells("SellingPrice").Value * 1
  19.                 If row.Cells("chk").Value = True Then
  20.                     'before adding check if the product is already added to the list
  21.                     For i = 0 To .RowCount - 1
  22.                         If pID = .Item(2, i).Value Then
  23.                             counter = counter + 1
  24.                             If counter <> 0 Then
  25.                                 'if item exist do not add
  26.  
  27.                             End If
  28.                         End If
  29.                     Next i
  30.                     If counter = 0 Then
  31.                         Dim R As DataRow = dt.NewRow
  32.                         R("Delete") = "Delete"
  33.                         R("lookup") = "Select"
  34.                         R("Product_ID") = pID
  35.                         R("pCode") = pcode
  36.                         R("description") = desc
  37.                         R("uom") = uom
  38.                         R("unit_price") = price
  39.                         R("qty") = 1
  40.                         R("total") = total
  41.                         R("disc_percentage") = 0
  42.                         R("disc_amount") = 0
  43.                         R("gtotal") = total
  44.                         'R("item_for") = "q"
  45.                         'R("returned_status") = "sold"
  46.                         'R("transaction_id") = selected_ID
  47.                         'R("user_ID") = 0
  48.                         dt2 = pForm.QformEdit.dgvData.DataSource
  49.                         dt.Rows.Add(R)
  50.                         dt2.Merge(dt, True, MissingSchemaAction.Ignore)
  51.                         pForm.QformEdit.dgvData.DataSource = dt2
  52.                     End If
  53.                 End If
  54.             Next
  55.             'MessageBox.Show(pID & "" & pcode & " " & pname)
  56.         End With
Add Comment
Please, Sign In to add comment