gpt4 book ai didi

c# - 禁用或灰显 DataGridView

转载 作者:IT王子 更新时间:2023-10-29 04:29:49 37 4
gpt4 key购买 nike

是否有任何简单的方法来禁用/灰显 DataGridView?比如在做的时候

dgv.Enabled = false

dgv 的外观没有改变。我看到有人附加了以下内容:

dgv.forecolor = gray
dgv.columnheader.forecolor = gray

但是,这看起来很笨拙。有没有更好的办法?

最佳答案

Private Sub DataGridView1_EnabledChanged(sender As Object, e As EventArgs) Handles DataGridView1.EnabledChanged
If Not DataGridView1.Enabled Then
DataGridView1.DefaultCellStyle.BackColor = SystemColors.Control
DataGridView1.DefaultCellStyle.ForeColor = SystemColors.GrayText
DataGridView1.ColumnHeadersDefaultCellStyle.BackColor = SystemColors.Control
DataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = SystemColors.GrayText
DataGridView1.CurrentCell = Nothing
DataGridView1.ReadOnly = True
DataGridView1.EnableHeadersVisualStyles = False
Else
DataGridView1.DefaultCellStyle.BackColor = SystemColors.Window
DataGridView1.DefaultCellStyle.ForeColor = SystemColors.ControlText
DataGridView1.ColumnHeadersDefaultCellStyle.BackColor = SystemColors.Window
DataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = SystemColors.ControlText
DataGridView1.ReadOnly = False
DataGridView1.EnableHeadersVisualStyles = True
End If
End Sub

关于c# - 禁用或灰显 DataGridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8715459/

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