Gray Out Entire Grid

PhillD

Well-known member
Joined
Mar 5, 2010
Messages
91
Programming Experience
10+
Does anyone have any code that would effectively cause a datagridview to appear though it is disabled. I have a situation where I enable/disable the grid and need to provide visual indication to the user.

I have been playing with it but there seems like a lot of options that need to be configured to make it appear the way, in addition, it looked like each column had to be set individually.

Is there a way to loop through all the columns and set the necessary settings?

Thanks
 
DataGridView does not change appearance when Enabled=False | Microsoft Connect
Accordingly you can for example do this when toggling Enabled:
VB.NET:
If Me.DataGridView1.Enabled Then
    Me.DataGridView1.Enabled = False
    Me.DataGridView1.DefaultCellStyle.BackColor = SystemColors.Control
    Me.DataGridView1.DefaultCellStyle.ForeColor = SystemColors.GrayText
    Me.DataGridView1.CurrentCell = Nothing
Else
    Me.DataGridView1.Enabled = True
    Me.DataGridView1.DefaultCellStyle.BackColor = SystemColors.Window
    Me.DataGridView1.DefaultCellStyle.ForeColor = SystemColors.ControlText
End If
 
Thanks for this, I also added

VB.NET:
            Me.DataGridView1.ColumnHeadersDefaultCellStyle.BackColor = SystemColors.Control
            Me.DataGridView1.ColumnHeadersDefaultCellStyle.ForeColor = SystemColors.GrayText

for the column headers.
 
Back
Top