Implementing "Select All" Checkbox

7 posts, 0 answers
  1. Support
    Support avatar
    9 posts
    Member since:
    Oct 2012

    Posted 20 Nov 2012 Link to this post

    Hi there,

    I am having some trouble implementing a "select all" checkbox for the RadGridView. I have successfully added checkboxes to group headers as shown in the attached screenshot. I need the ability to tick a box (which sits outside the grid) so it will select or deselect all items in the grid. 

    Currently when I click on the "select all" checkbox, only four items are selected in the grid out of 131. I believe this has something to do with the control reusing cells. I have implemented the following class.

    public class CustomGroupCellHeader : GridGroupContentCellElement
            public event EventHandler CheckChanged;
            public RadCheckBoxElement Checkbox { get; set; }
            public GridViewColumn Column { get; set; }
            public GridRowElement Row { get; set; }
            public Guid OperatorId { get; set; }
            public string OperatorName { get; set; }
            public CustomGroupCellHeader(GridViewColumn column, GridRowElement row) :
                base(column, row)
                this.Column = column;
                this.Row = row;
            protected override void CreateChildElements()
                this.Checkbox = new RadCheckBoxElement();
                this.Checkbox.MinSize = new Size(10, 10);
                this.Checkbox.ToggleStateChanged += new StateChangedEventHandler(_checkbox_ToggleStateChanged);
                this.Children.Insert(0, this.Checkbox);
            protected override System.Drawing.SizeF ArrangeOverride(System.Drawing.SizeF finalSize)
                SizeF size = base.ArrangeOverride(finalSize);
                RectangleF rect = GetClientRectangle(finalSize);
                if (this.Checkbox != null)
                    this.Checkbox.Arrange(new RectangleF(rect.X, rect.Y + 5, 10, 10));
                return size;
            private void _checkbox_ToggleStateChanged(object sender, StateChangedEventArgs args)
                if (this.CheckChanged != null)
                    this.CheckChanged(this, null);

    I have also added the following code into the CreateCell event handler:

    private List<CustomGroupCellHeader> _groupCheckboxes = new List<CustomGroupCellHeader>();
    private void results_CreateCell(object sender, GridViewCreateCellEventArgs e)
        if (e.CellType == typeof(GridGroupContentCellElement))
            CustomGroupCellHeader customCell = new CustomGroupCellHeader(e.Column, e.Row);
            customCell.CheckChanged += new EventHandler(customCell_CheckChanged);
            e.CellElement = customCell;

    The variable _groupCheckboxes is intended to store the checkboxes for group headers. How can I ensure that this variable stores ALL checkboxes for group headers?

  2. Svett
    Svett avatar
    728 posts

    Posted 22 Nov 2012 Link to this post

    Hello Magnetism,

    It seems that the implementation of the custom group cell element is correct. Nevertheless, I cannot determine the implementation the CheckChanged event handler. Could you share a code snippet that shows its actual implementation? Meanwhile, you can select all child rows of a particular group row by using the following code snippet in your custom cell:

    private void _checkbox_ToggleStateChanged(object sender, StateChangedEventArgs args)
        GridViewGroupRowInfo groupRow = this.RowInfo as GridViewGroupRowInfo;
        bool isSelected = args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On;
        foreach (GridViewRowInfo row in groupRow.ChildRows)
            row.IsSelected = isSelected;

    All the best,
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  3. Nomesh
    Nomesh avatar
    1 posts
    Member since:
    Oct 2016

    Posted 18 Oct 2016 in reply to Svett Link to this post

    Hi Team,

    I am working on Multilevel Gridview in winforms( 4 Levels)

    I have Select All Header Checkbox in the GrdiviewCheckBoxColumn in all the four levels.

    My requirement is,

    When I check/Uncheck the Header Checkbox in one of the levels, I need to change the toggle state of the Header checkboxes automatically in the remaining levels.

    For Eg..  If I check the HeaderCheckbox in first level, all the HeaderCheckboxes in the second, third and fourth levels should be checked automatically

    If I check the HeaderCheckbox in second level, all the HeaderCheckboxes in the third and fourth levels should be checked automatically.




  4. Dess | Tech Support Engineer, Sr.
    Dess | Tech Support Engineer, Sr.  avatar
    4086 posts

    Posted 19 Oct 2016 Link to this post

    Hello Nomesh,

    Thank you for writing.  

    Note that since Q2 2014 SP1, RadGridView supports header checkbox in the GridViewCheckBoxColumn. It is just necessary to set the GridViewCheckBoxColumn.EnableHeaderCheckBox property to true. However, to check/uncheck the inner levels, it is necessary to do it programmatically. You can handle the RadGridView.HeaderCellToggleStateChanged event and iterate all the inner templates and their Rows collection and update the respective boolean cell value.
    As to the specific custom implementation for the header checkbox, please refer to the attached sample project which result is illustrated in the attached gif file. Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify it in a way which suits your requirement best.
    I hope this information helps. Should you have further questions I would be glad to help.

    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  5. Ariel
    Ariel avatar
    1 posts
    Member since:
    Feb 2016

    Posted 27 Jun 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    I need this functionality. But, after compiling the code, it doesn't match the gif. I set EnableHeaderCheckBox to true to see if that would fix it, but it still didn't work.
  6. Dess | Tech Support Engineer, Sr.
    Dess | Tech Support Engineer, Sr.  avatar
    4086 posts

    Posted 01 Jul 2019 Link to this post

    Hello, Ariel,  

    If you run the sample project provided in my previous reply with the latest version of the Telerik UI for WinForms suite, it is necessary to make the following change in the CreateCell event handler:

    private void radGridView1_CreateCell(object sender, GridViewCreateCellEventArgs e)
        if (e.CellType == typeof(GridCheckBoxHeaderCellElement) && e.Column is GridViewCheckBoxColumn)
            e.CellElement = new CheckBoxHeaderCell(e.Column, e.Row);

    Thus, you will use the custom cell and update the child cells as well when toggling the checkbox in the parent's header.

    I hope this information helps. If you need any further assistance please don't hesitate to contact me.

    Dess | Tech Support Engineer, Sr.
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  7. Sudha
    Sudha avatar
    2 posts
    Member since:
    Mar 2016

    Posted 05 Jul 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    Hi Dess

    This works fine. But I think there may be an issue. Could you please clarify? When the header checkbox is clicked, it correctly checks the children header and data rows. But when I check a data row of a parent data row, I would expect its children and hierarchy below all get selected. But it doesn't do that. I think when a parent data row is checked all its children header and data rows must be checked as well. See the screenshot attached. Even though Parent1 is selected its children are not. Could you please help me fix this issue?



Back to Top