在cellformatting事件后刷新datagridview

时间:2017-01-24 01:01:48

标签: vb.net datagridview fonts runtime cell-formatting

我正在使用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中单元格的样式

感谢您的帮助......

0 个答案:

没有答案
相关问题