New to Telerik UI for WinForms? Download free 30-day trial

Check only one checkbox in GridViewCheckBoxColumn

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:

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.

In this article