如何在vb.net

时间:2017-10-12 01:28:18

标签: vb.net

我遇到的问题是如何只将datagridview1中特定行的正数据传递给datagridview2。

例如;

这是我在datagridview1

中的数据
 Code     ProductID    Description           Balance
 C1        0001        Office Furnitures     10,000.00
 C2        0002        Steel Cabinets        10,000.00
 C3        0003        Swivle Chair           3,500.00
 C4        0004        Monitor               -5,000.00
 C5        0005        Keyboard                -750.00
 C6        0006        Mouse                   -500.00

仅将具有正值的数据传递给Datagridview2

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

我已经尝试过这段代码并且工作正常但是将所有数据从datagridview1传递到datagridview以包含具有负值的行:

 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

我不知道如何扭曲代码让我得到结果。任何帮助表示赞赏。感谢

1 个答案:

答案 0 :(得分:0)

我能够解决自己的问题。如果您有兴趣,这是代码。享受!

 Dim n As Integer = 0
    For Each r As DataGridViewRow In dgvSTSub.Rows
        If dgvSTSub.Rows.Count <> n + 1 Then
            StudentTransaction.dgvReceipt.Rows.Add()
            If r.Cells(0).Value > 0 Then
                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
        End If
        n += 1