i have 4 columns in first datagridview which is
dgvProducts
:
item id
item name
price
category
and 4 columns also in my 2nd datagridview named
dgvCart
:
item id
item name
price
quantity
when a row in
dgvProducts
is clicked, there will be a dialogbox that prompts them if how many are they going to order in that specific product.. in that dialogbox there is a label,
txtbox(txtQuantity)
and a button(Add to Cart). the values in 1st, 2nd, 3rd cell of dgvProducts selected row is copied going to 1st, 2nd and 3rd cell of dgvCart. and the value for 4th cell of dgvCart will come from the txtQuantity.
i used this code to bind data from a DB Access to dgvProducts:
Dim X As New OleDb.OleDbConnection("Provider = microsoft.jet.oledb.4.0; data source = SourceFile.mdb")
Dim Y As New OleDb.OleDbDataAdapter("Select * from tbkProducts", X)
im creating bakery ordering system.
dgvProducts
is connected to a DB MS Access.
dgvCart
is empty. (just have columns, created via designer property)
i tried the code below but it copies all the cell values in a selected row. and only the first row is being copied to the other datagridview. pls im new in using datagridview i really need help. what should i change in the code?
thank you in advance.
What I have tried:
Private Sub dgvProducts_CellMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgvProducts.CellMouseClick
If dgvCart.Columns.Count = 0 Then
For Each dgvc As DataGridViewColumn In dgvProducts.Columns
dgvCart.Columns.Add(TryCast(dgvc.Clone(), DataGridViewColumn))
Next
End If
Dim row As New DataGridViewRow()
For i As Integer = 0 To dgvProducts.Rows.Count = 1
row = DirectCast(dgvProducts.Rows(i).Clone(), DataGridViewRow)
Dim intColIndex As Integer = 0
For Each cell As DataGridViewCell In dgvProducts.Rows(i).Cells
row.Cells(intColIndex).Value = cell.Value
intColIndex += 1
Next
dgvCart.Rows.Add(row)
Next
End Sub