问题描述
我在第一个datagridview中有4列是 dgvProducts
:
i have 4 columns in first datagridview which is dgvProducts
:
item id
item name
price
category
和我的第二个datagridview中的4列名为 dgvCart
:
and 4 columns also in my 2nd datagridview named dgvCart
:
item id
item name
price
quantity
dgvProducts 中的一行时,会出现一个对话框,提示他们是否有多少人会去在该特定产品中订购..在该对话框中有一个标签, txtbox(txtQuantity)
和一个按钮(添加到购物车)。将dgvProducts选定行的第1,第2,第3单元格中的值复制到dgvCart的第1,第2和第3单元格。 dgvCart的第四个单元格的值将来自txtQuantity。
i使用此代码将数据从DB Access绑定到dgvProducts:
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)
即时创建面包店订购系统。
dgvProducts
已连接到DB MS Access。
dgvCart
为空。 (只有列,通过设计师属性创建)
我尝试了下面的代码,但它复制了所选行中的所有单元格值。并且只将第一行复制到其他datagridview。请使用datagridview我真的需要帮助。我应该在代码中更改什么?
提前谢谢。
我尝试了什么:
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
推荐答案
这篇关于Datagridview:如何将所选行的一些单元格值从datagridview复制到另一个datagridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!