This is a migrated thread and some comments may be shown as answers.

Select \ Deselect all checkbox inside row

1 Answer 81 Views
GridView
This is a migrated thread and some comments may be shown as answers.
dan
Top achievements
Rank 1
dan asked on 15 May 2014, 02:31 PM
I have GridView with several columns:

number 1 Checkbox (called "Select all")
number 2 test line
number 3 Checkbox
number 4 Checkbox

What i want to do is once the Checkbox from the first column is selected so i want automatic select Checkbox number 3 and 4 (all the checkbox inside the row except the first of curse...)

so this is what i have try:

        private void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
        {
            if ((bool)e.RowElement.RowInfo.Cells["Select"].Value)
            {
                e.RowElement.RowInfo.Cells["First Name"].Value = true;
                e.RowElement.RowInfo.Cells["Second Name"].Value = true;
            }
            else
            {
                e.RowElement.RowInfo.Cells["First Name"].Value = false;
                e.RowElement.RowInfo.Cells["Second Name"].Value = false;
            }
        }
the only problem that i have is once selected the first checkbox  of several rows and all checkbox selected is i want to deselect specific checkbox this also select \ deselect other rows checkbox










1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 19 May 2014, 12:11 PM
Hello Dan,

Thank you for writing.

To achieve the desired behavior you can subscribe to the editor's ValueChanged event and change the values accordingly.  
void editor_ValueChanged(object sender, EventArgs e)
{
    bool value = (ToggleState)((RadCheckBoxEditor)sender).Value == ToggleState.On;
    radGridView1.CurrentRow.Cells["column3"].Value = value;
    radGridView1.CurrentRow.Cells["column4"].Value = value;
    
}

You can subscribe to this event in the CellEditorInitialized event (I have added an unsubscription before the subscription to avoid multiple subscriptions since the editors are reused):
void radGridView1_CellEditorInitialized(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
{
    if (e.Column.Name == "column1")
    {
        RadCheckBoxEditor editor = e.ActiveEditor as RadCheckBoxEditor;
        editor.ValueChanged -= editor_ValueChanged;
        editor.ValueChanged += editor_ValueChanged;
    }
}

Additional information about the editor's events is available in the following article: Handling Editors' events.

Let me know if you have additional questions.
 
Regards,
Dimitar
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
dan
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or