dataGridView1.CellClick += (sender, e) =>
{
if (e.ColumnIndex == 0)
{
InvoiceDetail curRow = dataGridView1.Rows[e.RowIndex].DataBoundItem as InvoiceDetail;
string mainId = curRow.Id_main;
bool isChecked = !curRow.Selected;
dataGridView1[e.ColumnIndex, e.RowIndex].Value = isChecked;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.DataBoundItem is InvoiceDetail cust)
{
if (cust.Id_main == mainId)
{
cust.Selected = isChecked;
}
}
}
dataGridView1.EndEdit();
dataGridView1.Refresh();
}
};