Take the 2-minute tour ×

I have a winForm with a DataGridView control. It contains 5 columns, one of them is a CheckBox column. I want to enable/disable checkbox cell of this column based on the value present in another column at the same row.

I can disable entire column using DisabledCheckBoxCell

But it makes entire column in disabled state.

Here is a snippet of DataGridView,

SourceColumn | DestinationColumn
true                  | enabled
true                  | enabled
false                 | disabled

Does anyone have idea, how this can be achieved in .Net.

Thanks in advance,

share|improve this question

3 Answers 3


DataGridViewCheckBoxColumn does not have property called disabled so by changing the style of the checkbox you can make it look like as if it is disabled. Look at the following code.

 private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        if (e.RowIndex == 1)
            DataGridViewCell cell=dataGridView1.Rows[e.RowIndex].Cells[0];
            DataGridViewCheckBoxCell chkCell = cell as DataGridViewCheckBoxCell;
            chkCell.Value = false;
            chkCell.FlatStyle = FlatStyle.Flat;
            chkCell.Style.ForeColor = Color.DarkGray;
            cell.ReadOnly = true;


share|improve this answer
Thanks for your reply. This is working with some minor issues. I have checkbox cells in column headers as well. This is affecting them too. When I switch to other App and return to the original App, UI looks distorted. –  Vijay Balkawade May 4 '12 at 5:26

You can not Visible proerty in RowPostPaint Event of DataGridView Beacuse it is readonly property.

How can do this things..

share|improve this answer

Try using RowDataBound event for your GridView. You can cast eventargs to row, find control on this row and disable it. This event fires for each row of gridview, even for headers and footers, so try not to catch exception. Here is some code might be useful to you

protected void xxx_RowDataBound(object sender, GridViewRowEventArgs e)
    if ((e.Row != null) && e.Row.RowType == DataControlRowType.DataRow)
share|improve this answer
I want to disable the cell in respective row, I could not find enabled property on a Cell. I am using RowPostPaint event. –  Vijay Balkawade Apr 26 '12 at 12:00
Ins't it winforms? –  Johnny_D Apr 26 '12 at 12:21
I am afraid there may not be any function to disable an individual cell, but you can do something while the cell is clicked, for example to revert the value for the cell you wan to disable –  Nick Apr 27 '12 at 0:24
Yes I tried that as well on CellEndEdit event, but it is not respected. The check box still shows the current state ( checked/unchecked). –  Vijay Balkawade Apr 27 '12 at 4:02
@Johnny_D yes, it is a WinForm application. –  Vijay Balkawade Apr 27 '12 at 4:03

Your Answer


