Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello!
I used to have a project in which my datagridview have a checkboxcolumn, created dynamically. I implemented this code in CellEditEnding event, to prevent more then one checkbox from being checked..



C#
if (e.ColumnIndex == 0) //column index
        {
            bool hasOtherCheckboxChecked = false;
            foreach (DataGridViewRow dgvr in dataGridView1.Rows)
            {
                DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)dgvr.Cells[e.ColumnIndex];
                if (cell.Value == cell.TrueValue && dgvr.Index != e.RowIndex)
                {
                    hasOtherCheckboxChecked = true;
                    break;
                }
            }
            DataGridViewCheckBoxCell currentCell = (DataGridViewCheckBoxCell)dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
            if (currentCell.Value == currentCell.TrueValue && hasOtherCheckboxChecked)
            {
                currentCell.Value = currentCell.FalseValue;
            }
        }



Now, i migrated my aplication too a wpf format, and i cant use this anymore.
Can anyone help me. maybe in converting the code, or sugesting another alternative that doesnt required setting autogeneratecolumn to false.

Please help!
Thanks in advance.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900