DataGridViewCheckBoxColumn Checked

1

I have a check in the DataGridView, I wanted to know if it is possible that every time a value is added automatically it appears as checked

    
asked by Alejandro Ricotti 20.12.2016 в 14:48
source

1 answer

4

It can be done, of course. First, you could control each time a new row is added to DataGridView by handling the event RowsAdded and then set the value of the cell of type DataGridViewCheckBoxColumn in this way:

private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
{
    // e.RowIndex proporciona el índice de la fila que se acaba de añadir
    dataGridView1.Rows[e.RowIndex].Cells["NombreDeTuCeldaCheckBox"].Value = true;
}

But beware, if your DataGridView had previous data, it would save the amount of existing records in a variable and check that the new index was greater than that amount, or otherwise you would mark all the CheckBoxes.

    
answered by 20.12.2016 / 15:26
source