2017-10-12 43 views
0

我曾經遇到過如何僅將datagridview1中特定行的數據傳遞給datagridview2的問題。如何將datagridview1中的正值傳遞給vb.net中的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 

我不知道如何扭轉代碼來獲得結果。任何幫助表示讚賞。謝謝

回答

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 
相關問題