【问题标题】:how to Pass only positive values from datagridview1 to datagridview2 in vb.net如何在 vb.net 中仅将正值从 datagridview 传递到 datagridview 2
【发布时间】:2017-10-12 01:28:17
【问题描述】:

关于如何仅将 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

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

【问题讨论】:

    标签: vb.net


    【解决方案1】:

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

     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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 2015-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多