How to add a CheckBox type column in DataGridView?
I need to do this for the user to select the row of the DataGridView with the CheckBox and then click the Save button.
private void btnRestricao_Click_2(object sender, EventArgs e)
{
OleDbDataReader dr = null;
try
{
this.pnlModalMotivo.Visible = true;
dr = MotivoNegocio.ListarMotivo();
for (int i = 0; i < dr.FieldCount; i++)
{
DataGridViewColumn coluna = new DataGridViewTextBoxColumn();
coluna.HeaderText = dr.GetName(i);
coluna.Visible = true;
coluna.Name = "coluna" + 1;
coluna.Resizable = DataGridViewTriState.True;
dgvMotivo.Columns.Add(coluna);
}
while (dr.Read())
{
object[] campos = new object[dr.FieldCount];
for (int i = 0; i < dr.FieldCount; i++)
campos[i] = dr.GetValue(i);
dgvMotivo.Rows.Add(campos);
}
}
catch(Exception ex)
{
MessageBox.Show("Erro: " + ex.Message);
}
}