.net – 当SelectionMode = FullRowSelect时,如何突出显示DataGridView中的当前单元格

前端之家收集整理的这篇文章主要介绍了.net – 当SelectionMode = FullRowSelect时,如何突出显示DataGridView中的当前单元格前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个可编辑的DataGridView,SelectionMode设置为FullRowSelect(因此当用户点击任何单元格时整个行都会突出显示).但是,我希望当前具有焦点的单元格以不同的背景颜色突出显示(因此用户可以清楚地看到他们将要编辑的单元格).我该怎么做(我不想改变SelectionMode)?
我想出了一个更好的方法,使用CellFormatting事件:
Private Sub uxContacts_CellFormatting(ByVal sender As Object,ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles uxContacts.CellFormatting
    If uxContacts.CurrentCell IsNot Nothing Then
        If e.RowIndex = uxContacts.CurrentCell.RowIndex And e.ColumnIndex = uxContacts.CurrentCell.ColumnIndex Then
            e.CellStyle.SelectionBackColor = Color.SteelBlue
        Else
            e.CellStyle.SelectionBackColor = uxContacts.DefaultCellStyle.SelectionBackColor
        End If
    End If
End Sub

猜你在找的VB相关文章