【发布时间】:2019-01-27 02:15:43
【问题描述】:
在我的表单上,我有一个 datagridview。我还有一个包含以下值的文本文件:
PersonName:PersonAge:ChampionTrueOrFalse
当调用 sub 时,文本文件中的所有值都会加载到数组中,第一个值(人名)会显示在 datagridview 中。 我想要实现的是:如果个人第四个值(ChampionTrueOrFalse)的值为真,则将该特定行的背景颜色为黄色。
我得到的最接近的是以下内容,但是当它应该只为列中具有“False”的单元格着色时,它会将所有单元格变为绿色。
Private Sub DataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
For Each row1 As DataGridViewRow In DataGridView1.Rows
If row1.Cells("ChampionTrueOrFalse").Value = "Yes" Then
e.CellStyle.BackColor = Color.LightGreen
End If
Next
End Sub
【问题讨论】:
-
没有必要迭代该事件中的所有行。事件 args 将告诉您需要绘制哪一行。看看骗局
标签: vb.net datagridview