I've create an application which displays a DataGridView with a series of questions.
The dgv structure consists of one string column for the question text and three bool/checkbox columns for the answers (yes, no, N/A).
Each single question is displayed on its own row.
I would like my program to only allow the user to select only Yes, only No or only N/A on each row.
I think I would need to uncheck the other checkbox options when one option is checked but I'm not too sure on how to do this.
I've setup CellValueChanged and CellContentClick events but I'm unsure of the code needed to achieve the desired functionality.
DataGridView is bound to a DataTable.
Code I have so far:
private void dgvQuestions_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
int columnIndex = e.ColumnIndex;
int rowIndex = e.RowIndex;
DataGridViewCheckBoxCell chkYes = dgvQuestions.Rows[rowIndex].Cells[2] as DataGridViewCheckBoxCell;
DataGridViewCheckBoxCell chkNo = dgvQuestions.Rows[rowIndex].Cells[3] as DataGridViewCheckBoxCell;
DataGridViewCheckBoxCell chkNA = dgvQuestions.Rows[rowIndex].Cells[4] as DataGridViewCheckBoxCell;
if (Convert.ToBoolean(chkYes.Value) == true)
{
}
if (Convert.ToBoolean(chkNo.Value) == true)
{
}
if (Convert.ToBoolean(chkNA.Value) == true)
{
}
}
private void dgvQuestions_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
dgvQuestions.CommitEdit(DataGridViewDataErrorContexts.Commit);
}