根据单元格值的数量更改DataGridView中的行颜色 [英] Change the row color in DataGridView based on the quantity of a cell value
本文介绍了根据单元格值的数量更改DataGridView中的行颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在datagridview中更改一行的颜色,但是我的代码不适用于我。
我总是得到一个错误,表示不能找到列的数量:参数名称:columnName
I need to change the color of a row in datagridview but my code is not working for me. I always get a error that says "Column named Quantity: cannot be found. Parameter name: columnName"
这是我的代码:
Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
For i As Integer = 0 To Me.DataGridView1.Rows.Count - 1
If Me.DataGridView1.Rows(i).Cells("Quantity:").Value < 5 Then
Me.DataGridView1.Rows(i).Cells("Quantity:").Style.ForeColor = Color.Red
End If
Next
End Sub
请帮我修复它。谢谢。
推荐答案
我修复了我的错误。刚刚从这一行中删除了Value:
I fixed my error. just removed "Value" from this line:
If drv.Item("Quantity").Value < 5 Then
所以它看起来像
如果drv.Item(Quantity)< 5然后
这篇关于根据单元格值的数量更改DataGridView中的行颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文