发了贴子,自己突然就有想法了,郁闷,我的方法是
For i = 0 To GridView1.Rows.Count - 1
Dim BZ As String = GridView1.DataKeys(i).Item(5).ToString
If BZ = 0 Then
GridView1.Rows(i).BackColor = System.Drawing.Color.Yellow
Else
GridView1.Rows(i).BackColor = System.Drawing.Color.Blue
end if
next
大家还有什么更好的方法还请赐教啊!
我这样写的,不知道是不是合适,希望高手指正
Private Sub dvg库存图纸_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dvg库存图纸.CellValueChanged
With dvg库存图纸
If e.RowIndex <= .Rows.Count - 1 Then
If .Rows(e.RowIndex).Cells("库存数量").Value = 0 Then
.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Red
.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.White
ElseIf .Rows(e.RowIndex).Cells("库存数量").Value <> 0 And .Rows(e.RowIndex).Index Mod 2 = 0 Then
.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.YellowGreen
.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Black
ElseIf .Rows(e.RowIndex).Cells("库存数量").Value <> 0 And .Rows(e.RowIndex).Index Mod 2 <> 0 Then
.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.GreenYellow
.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Black
End If
End If
End With
End Sub
Private Sub dvg库存图纸_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dvg库存图纸.CellValueChanged
With dvg库存图纸
If e.RowIndex <= .Rows.Count - 1 Then
If .Rows(e.RowIndex).Cells("库存数量").Value = 0 Then
.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.Red
.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.White
ElseIf .Rows(e.RowIndex).Cells("库存数量").Value <> 0 And .Rows(e.RowIndex).Index Mod 2 = 0 Then
.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.YellowGreen
.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Black
ElseIf .Rows(e.RowIndex).Cells("库存数量").Value <> 0 And .Rows(e.RowIndex).Index Mod 2 <> 0 Then
.Rows(e.RowIndex).DefaultCellStyle.BackColor = Color.GreenYellow
.Rows(e.RowIndex).DefaultCellStyle.ForeColor = Color.Black
End If
End If
End With
End Sub