You can add the code to a button event and then loop through each row to do your validation for 'Yes'. I have adapted the code a little where if multiple 'Yes' options were selected, it deselects the other options and keeps only one 'Yes' option selected. -
private void btnValidate_Click(object sender, EventArgs e)
{
DataGridViewComboBoxColumn comboBoxColumn = dataGridView1.Columns["kbaskani"] as DataGridViewComboBoxColumn;
if (comboBoxColumn != null)
{
int yesCount = 0;
int rowIndexWithMultipleYes = -1;
for (int rowIndex = 0; rowIndex < dataGridView1.Rows.Count; rowIndex++)
{
DataGridViewRow row = dataGridView1.Rows[rowIndex];
string cellValue = row.Cells[comboBoxColumn.Index].Value?.ToString();
if (cellValue == "Evet")
{
yesCount++;
if (yesCount > 1)
{
rowIndexWithMultipleYes = rowIndex;
break;
}
}
}
if (yesCount == 0)
{
MessageBox.Show("You haven’t chosen any Yes option. You have to choose one of the Yes options.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (yesCount > 1)
{
MessageBox.Show("You have chosen more than one Yes option. You can choose only one Yes option.", "Validation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
else if (rowIndexWithMultipleYes != -1)
{
for (int rowIndex = 0; rowIndex < dataGridView1.Rows.Count; rowIndex++)
{
if (rowIndex != rowIndexWithMultipleYes)
{
dataGridView1.Rows[rowIndex].Cells[comboBoxColumn.Index].Value = "Hayır";
}
}
}
}
}