New to Telerik UI for WinForms? Start a free 30-day trial
Check only one checkbox in GridViewCheckBoxColumn
Updated over 6 months ago
| Product Version | Product | Author | Last modified |
|---|---|---|---|
| Q3 2009 SP1 | RadGridView for WinForms | Nikolay Diyanov | Jan 13, 2009 |
INTRODUCTION
By default, GridViewCheckBoxColumn allows for multiple checked checkboxes. However, in certain cases you may want to use it as a kind of RadioButton column - i.e. allow the user to check only one checkbox at a time.
SOLUTION
In order to implement the desired requirement, first subscribe to the ValueChanged event and then execute the following code snippet in the ValueChanged event handler:
C#
void radGridView1_ValueChanged(object sender, EventArgs e)
{
RadCheckBoxEditor editor = sender as RadCheckBoxEditor;
if (editor != null && (bool)editor.Value == true)
{
this.radGridView1.GridElement.BeginUpdate();
foreach (GridViewDataRowInfo row in this.radGridView1.Rows)
{
if (row != this.radGridView1.CurrentRow)
{
row.Cells["Bool"].Value = false;
}
}
this.radGridView1.GridElement.EndUpdate();
}
}
Basically, we first check if the current editor is RadCheckBoxEditor and if the editor's value is true. If this case is true, we set the value of all the cells contained in the current column, but not contained in the current row to false.