2017-10-05 40 views
0

我得到了這個問題,如何確定datagridview中的下一行是否等於負數,然後當前行將返回一個備註。如何確定datagridview中的下一行是否等於負整數?

例如;

Remarks Reference 
    A   1 
    A   2 
    B   3 
      -4 

如果下一行是一個正數,發言將是A.如果下一行是負值,言論將返回B.

我掙扎在這一部分。

下面是代碼:

For Each r As DataGridViewRow In dgvSTSub.Rows 
     Bal = Bal + r.Cells(3).Value - r.Cells(1).Value 
     r.Cells(3).Value = Bal 

     If Bal > Bal + r.Cells(3).Value Then 
      r.Cells(2).Value = r.Cells(1).Value 
     End If 
    Next 

如上圖所示這是不實際的DataGridView但是這正是我希望發生的。

任何幫助/建議表示讚賞。

+0

請出示您的鬥爭這部分 – Plutonix

+0

對不起,我無法包含我的代碼。 – Diaval

+0

我編輯了我的帖子..請看看它。 – Diaval

回答

0

從給定的數據。備註是cells(0)和參考是cells(1)
cells(1)確定負整數:

假設引用包含整數只:(使用這些代碼)

Dim i As Integer = 0 
    Dim number As Integer 
    While i <= DataGridView1.RowCount - 1 
     number = CInt(DataGridView1.Rows(i).Cells(1).Value) 
     If number < 0 Then 
      MsgBox("Row: " & i & " is Negative number") ' Omit this line if you want. 
      ' Add your codes here 
     End If 
     i += 1 
    End While 
相關問題