Phi*_*lls 5 .net vb.net datagridview winforms
我有一个可编辑的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
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10885 次 |
最近记录: |