gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 18:04:59 25 4
gpt4 key购买 nike

我有一个可编辑的 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

关于.net - 当 SelectionMode=FullRowSelect 时,如何突出显示 DataGridView 中的当前单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com