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

Checking/unchecking check boxes in multiple rows at once

1 Answer 102 Views
GridView
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 22 Aug 2013, 03:31 PM
I want the user to be able to do this:
  1. User selects multiple rows
  2. User clicks the check box in a check box column
  3. If the check box clicked was unchecked before clicking then change the check boxes to checked in all selected rows, else change the check boxes to unchecked in all selected rows

The problem I am running into is that the selection seems to be cleared as soon as the check box is clicked.  Can you suggest a solution that would accomplish this behavior?

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 27 Aug 2013, 01:24 PM
Hello John,

Thank you for contacting Telerik Support.

In order to obtain the desired scenario, please have a look at the following code snippet:
public Form1()
{
    InitializeComponent();
 
    GridViewTextBoxColumn textBoxColumn = new GridViewTextBoxColumn("Product");
    radGridView1.MasterTemplate.Columns.Add(textBoxColumn);
 
    GridViewCheckBoxColumn checkBoxColumn = new GridViewCheckBoxColumn("Discontinued");
    radGridView1.MasterTemplate.Columns.Add(checkBoxColumn);
 
    this.radGridView1.Rows.Add("Product1", true);
    this.radGridView1.Rows.Add("Product2", false);
    this.radGridView1.Rows.Add("Product3", false);
    this.radGridView1.Rows.Add("Product4", false);
    this.radGridView1.Rows.Add("Product5", true);
    this.radGridView1.Rows.Add("Product6", false);
    this.radGridView1.Rows.Add("Product7", true);
    this.radGridView1.Rows.Add("Product8", false);
    this.radGridView1.Rows.Add("Product9", true);
     
    this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
    this.radGridView1.MultiSelect = true;
    this.radGridView1.SelectionMode = GridViewSelectionMode.FullRowSelect;
    this.radGridView1.ValueChanging += radGridView1_ValueChanging;
}
 
private void radGridView1_ValueChanging(object sender, ValueChangingEventArgs e)
{
    RadCheckBoxEditor editor = sender as RadCheckBoxEditor;
    if (editor != null)
    {
        foreach (GridViewDataRowInfo row in this.radGridView1.SelectedRows)
        {
            row.Cells[1].Value = e.NewValue;
        }
    }
}

Have in mind that when clicking the check box, you should keep Ctrl key pressed in order not to loose selected rows.

I hope this information helps. Should you have further questions, I would be glad to help.

Regards,
Desislava
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WINFORMS.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
John
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or