Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling or greying out a DataGridView

Tags:

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?

like image 529
Jeb Avatar asked Jan 03 '12 16:01

Jeb


People also ask

How to Disable DataGridView in c#?

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.

What is the use of DataGridView control?

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.

How delete all DataGridView?

I required it to clear all rows of datagridview on button click event. dataGridView1. Rows. Clear();


1 Answers

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 
like image 189
sveilleux2 Avatar answered Oct 01 '22 04:10

sveilleux2