Is there any easy way to disable/grey out a DataGridView? For instance when doing
dgv.Enabled = false
The appearance of the dgv does not change. I have seen people appending the following:
dgv.forecolor = gray dgv.columnheader.forecolor = gray
However, this seems clumsy. Is there a better way?
ControlLightLight for the DisableColor and 150 for the DisableColorAlpha to achieve a pretty good match to other disabled controls. This combination dims the text, which is missed when using Black. This approach also works for practically any other control that is missing the disabled look, including user controls.
The DataGridView control provides a powerful and flexible way to display data in a tabular format. You can use the DataGridView control to show read-only views of a small amount of data, or you can scale it to show editable views of very large sets of data.
I required it to clear all rows of datagridview on button click event. dataGridView1. Rows. Clear();
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With