title: Hide some datagridview checkbox cell
body: <p>I have a <code>datagridview</code> showing installments of a loan. I created a <code>datagridviewcheckbox</code> column so then I can select all the installments i want to pay for.</p>
  
  <p>This is a screen of the datagrid:</p>
  
  <p><img src="https://i.stack.imgur.com/G34ho.png" alt="enter image description here"></p>
  
  <p>My issue is that I need to disable the checkboxes of the paid intallments. In this case, when "Restante" (what´s left to pay) is <code>= 0</code>.</p>
  
  <p>I read some posts where they used the paint event to not show the checkbox cell, but i didnt like that solution. I thought of hiding the checkbox cell, but i don´t know if it is possible to do that.</p>
  
  <p>Thats what i tried:</p>
  
  <pre><code>foreach (DataGridViewRow row in dgv_Cuotas.Rows)
              {
                  if (Convert.ToDecimal(dgv_Cuotas.Rows[row.Index].Cells[17].Value) == 0)
                  {
                      dgv_Cuotas.Rows[row.Index].Cells[16].Visible = false;
                  }
              }
  </code></pre>
  
  <p>Obviously this does not works, I get a compiler error message saying that the property is read only.</p>
  
  <p>Does somebody knows how to set the checkbox cell to invisible?</p>
  
  <p>Just in case, I attach the <code>DataGridViewCheckboxColumn</code> creation code:</p>
  
  <pre><code>DataGridViewCheckBoxColumn chbox = new DataGridViewCheckBoxColumn();
              {
                  chbox.CellTemplate = new DataGridViewCheckBoxCell();
                  chbox.HeaderText = "";
                  chbox.Name = "Seleccionar";
                  chbox.AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                  chbox.FlatStyle = FlatStyle.Standard;
              }
              dgv_Cuotas.Columns.Insert(16, chbox);
              dgv_Cuotas.Columns[16].DisplayIndex = 0;
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>Some considerations:</p>
  
  <p>I use the cell content click event to handle the checkboxes, so readonly wont work. What I want is to hide the checkbox:</p>
  
  <pre><code>private void dgv_Cuotas_CellContentClick(object sender, DataGridViewCellEventArgs e)
      {
          if (e.RowIndex == -1)
              return;
          if (dgv_Cuotas.Columns[e.ColumnIndex].Name == "Seleccionar")
          {
              DataGridViewRow row = dgv_Cuotas.Rows[e.RowIndex];
              DataGridViewCheckBoxCell cellSeleccion = row.Cells["Seleccionar"] as DataGridViewCheckBoxCell;
              int n_cuota = Convert.ToInt32(dgv_Cuotas[2, dgv_Cuotas.CurrentRow.Index].Value);
              Cuota cuota_seleccionada = new Cuota();
              cuota_seleccionada = Lista_cuotas.Where(x =&gt; x.num_cuota == n_cuota).First();
  
              if (cellSeleccion != null &amp;&amp; Convert.ToBoolean(cellSeleccion.Value) == true)
              {
                  cellSeleccion.Value = false;
                  Actualizar_cuotas_seleccionadas(false, cuota_seleccionada);
              }
              else
              {
                  if (cellSeleccion != null &amp;&amp; Convert.ToBoolean(cellSeleccion.Value) == false)
                  {
                      cellSeleccion.Value = true;
                      Actualizar_cuotas_seleccionadas(true, cuota_seleccionada);
                  }
              }
          }
  </code></pre>
  
  <p>In the other hand, I´m already using the Onpaint event. Its inherited, thats why I´m trying to avoid using it.</p>