We help IT Professionals succeed at work.

How to grey out (or disable) column of checkboxes in datagridview (C#, Winform)

dominicwong
dominicwong used Ask the Experts™
on
Hi experts
I have a datagridview that contains a column of checkboxes.

I would like to grey out (or disable) the column programmatically. I tried ".ReadOnly" but that only disallowed user from using it. I want to make it visually show that it is not in use.

Thanks in advance
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010
Commented:
try this

dataGridView1.Rows[2].Cells[1].Style.BackColor =  Color.LightGray;
dataGridView1.Rows[2].Cells[1].ReadOnly = true;

Open in new window


further more.. you can loop and naviagte to any row and cell.

hope this helps!

Author

Commented:
Smart! Thanks masterpass.

I did this as I am interested in the whole column.
    dgv.Columns[1].ReadOnly = true;
    dgv.Columns[1].DefaultCellStyle.BackColor = Color.LightGray;

It doesn't grey out the checkbox (that would be ideal), but it serves the purpose.

Do you know, by any chance, any easy mean to grey out the checkboxes too?
Top Expert 2010

Commented:
unfortunately there is no easy way around the look of the checkbox. You will have to repaint the checkbox using code!

this will help u : http://www.codeproject.com/Articles/31829/Disabled-Checkbox-Column-in-the-DataGridView

hope this helps!
Top Expert 2010

Commented:
I think I provided the answer.

Author

Commented:
Sorry masterpass. It must be an accident. I thought I'd accepted your solution with the 500 points.

Moderator, kindly please fix this mistake and give the 500 points to masterpass for his help and excellent answer.

Author

Commented:
Closing this again. And thanks again to masterpass.