Below may or may not help as displayed as I took it from an old VB.NET project done over 10 years ago, ran it and worked, allows only one row to be checked. Next ran it through a converter what may or may not have gotten everything perfect.
public class Form1
{
private void InitializeInstanceData()
{
bsAnswers = new BindingSource();
}
private BindingSource bsAnswers;
private void Form1_Load(object sender, System.EventArgs e)
{
DataOperations ops = new DataOperations();
bsAnswers.DataSource = ops.ReadMockedData; // brings back a DataTable
DataGridView1.DataSource = bsAnswers;
DataGridView1.Columns("SelectionColumn").Width = 25; // the checkbox column
DataGridView1.Columns("SelectionColumn").HeaderText = "";
DataGridView1.Columns("OptionName").HeaderText = "";
}
private void DataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
var value = Convert.ToBoolean(DataGridView1.Rows(e.RowIndex).Cells("SelectionColumn").Value);
if (value)
{
int index = e.RowIndex;
for (int row = 0; row < DataGridView1.Rows.Count; row++)
{
if (row != index)
{
DataGridView1.Rows(row).Cells("SelectionColumn").Value = false;
}
}
}
else
{
DataGridView1.Rows(e.RowIndex).Cells("SelectionColumn").Value = true;
int index = e.RowIndex;
for (int row = 0; row < DataGridView1.Rows.Count; row++)
{
if (row != index)
{
DataGridView1.Rows(row).Cells("SelectionColumn").Value = false;
}
}
}
// Force cell painting
DataGridView1.CurrentCell = DataGridView1[0, e.RowIndex];
}
private void DataGridView1SelectAll_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (DataGridView1.CurrentCell is DataGridViewCheckBoxCell)
{
DataGridView1.EndEdit();
}
}
}