设置符合条件的DataGridView的行的颜色的两种方法

Private Sub dgvInfo_RowPrePaint(sender As Object, e As DataGridViewRowPrePaintEventArgs) Handles dgvInfo.RowPrePaint
For i = 0 To dgvInfo.Rows.Count - 1
Dim count As Integer = 0
count = DbHelperSQL.GetSingle("SELECT MinQty FROM dbo.tEquipment WHERE ID='" & dgvInfo.Rows(i).Cells("EquipmentID").Value & "'")
If dgvInfo.Rows(i).Cells("Qty").Value < count Then
dgvInfo.Rows(i).DefaultCellStyle.BackColor = Color.Red
End If
Next
End Sub

Private Sub dgvInfo_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles dgvInfo.CellFormatting
'For i = 0 To dgvInfo.Rows.Count - 1
' Dim count As Integer = 0
' count = DbHelperSQL.GetSingle("SELECT MinQty FROM dbo.tEquipment WHERE ID='" & dgvInfo.Rows(i).Cells("EquipmentID").Value & "'")
' If dgvInfo.Rows(i).Cells("Qty").Value < count Then
' If e.RowIndex = i Then
' e.CellStyle.BackColor = Color.Red
' End If
' End If
'Next
End Sub

posted @ 2014-05-25 19:29  xinsyong  阅读(2217)  评论(0编辑  收藏  举报