我在 Visual Basic Net 中编程,并手动用 MySql 表填充 Datagridview。如果满足某些条件,我想更改字体、行样式。
Datagridview.CellFormatting 事件可以做到这一点,但离开事件后,我的 datagridview 不会刷新。代码下方:
Private Sub gridUsers_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles gridUsers.CellFormatting
With DirectCast(sender, DataGridView)
If .CurrentRow.Cells("eliminado").Value Is "Si" Then
.CurrentRow.DefaultCellStyle.BackColor = Color.DarkRed
.CurrentRow.DefaultCellStyle.ForeColor = Color.White
ElseIf .CurrentRow.Cells("condicion").Value Is "No" Then
.CurrentRow.DefaultCellStyle.ForeColor = Color.DarkRed
.CurrentRow.DefaultCellStyle.Font = New Font("Verdana", 8, FontStyle.Strikeout Or FontStyle.Bold)
End If
End With
End Sub
我不知道为什么,但是每当我单击网格中的任何一行,或者向下和向上滚动时,线条的颜色都会改变。如何刷新datagridview中单元格的样式
谢谢你的帮助...