0

I have a DataGridView with a Button column in it.

I want to be able to disable and enable the buttons in every row (and/or change the style of them), according to a cell value in the row.

So let's say we have the following code :

if(dataGridView1.Rows[1].Cells[1].Value.ToString()=="OK")
        {
            //button in the same row should be enabled or disabled
        }

Can this be done?

Laureant
  • 979
  • 3
  • 18
  • 47

1 Answers1

0

You can inherit a DataGridViewDisableButtonCell class from DataGridViewButtonCell to use in your DGV, as explained on MSDN. Then you'll be able to enable/disable the button inside that cell with the following code:

DataGridViewDisableButtonCell buttonCell = (DataGridViewDisableButtonCell)dataGridView1.Rows[e.RowIndex].Cells["Buttons"];
buttonCell.Enabled = myEnableConditionMet ? true : false;
Patrice Gahide
  • 3,644
  • 1
  • 27
  • 37