繁体   English   中英

如何在 vb.net 中将数据从 Datagridview1 传递到 Datagridview2?

[英]How to pass data from Datagridview1 to Datagridview2 in vb.net?

我在如何将数据从 datagridview1 中的特定行传递到 datagridview2 时遇到了这个问题。

例如;

这是我在 datagridview1 中的数据

 Code     ProductID    Description           Price
 C1        0001        Office Furnitures     10,000.00
 C2        0002        Steel Cabinets        10,000.00
 C3        0003        Swivle Chair           3,500.00

将数据传递给 Datagridview2

 Product Description           Price
 Office Furnitures          10,000.00
 Steel Cabinets             10,000.00
 Swivle Chair                3,500.00

我想将 Datagridview1 中特定列的一些数据传递给 Datagridview2

拜托,我需要你的帮助。 谢谢

我找到了一个简单的答案来解决我的问题。 谢谢你@jmcilhinney..

这是代码:

Dim n As Integer = 0
    For Each r As DataGridViewRow In dgvSTSub.Rows
        If dgvSTSub.Rows.Count <> n + 1 Then
            StudentTransaction.dgvReceipt.Rows.Add()
            StudentTransaction.dgvReceipt.Rows(n).Cells(0).Value = r.Cells(2).Value.ToString()
            StudentTransaction.dgvReceipt.Rows(n).Cells(1).Value = r.Cells(0).Value
        End If
        n += 1
    Next

但是我的数据有另一个问题。 如果我的 datagridview1 中的某些项目为负值如何。 它应该只将正值返回到 datagridview2。 我将如何做? @jmcilhinney

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM