GridViewCheckBoxColumn Header checkbox selects/unselect only current page checkboxes

3 posts, 0 answers
  1. Betsy Lipschutz
    Betsy Lipschutz avatar
    4 posts
    Member since:
    Jul 2019

    Posted 25 May 2020 Link to this post



    I have one RadGridView for WinForm UI.

    I bind data dynamically using DataSource property and bind DataTable that is returned from database.

    Before binding datasource, I add a GridViewCheckBoxColumn to the RadGridView (for selecting all rows).


    following is the sample code:

    If RadGridView1.MasterTemplate.Columns.GetColumnByFieldName("").Length = 0 Then
                Dim checkBoxColumn As GridViewCheckBoxColumn = New GridViewCheckBoxColumn("")
                checkBoxColumn.EnableHeaderCheckBox = True
                checkBoxColumn.HeaderCheckBoxAlignment = ContentAlignment.MiddleCenter
                checkBoxColumn.AllowFiltering = False
                checkBoxColumn.CheckFilteredRows = False
                checkBoxColumn.HeaderText = String.Empty

                AddHandler RadGridView1.HeaderCellToggleStateChanged, AddressOf RadGridView1_HeaderCellToggleStateChanged
            End If


    Later I bind the data table:

    RadGridView1.DataSource = dataTable


    Now, I have 2 problems:

    1. Checking / Unchecking header check box, checks/unchecks checkboxes of current page only.  I need to perform the operation for the whole grid.

    2. I have got filters on.  User can select filters on columns.  Once filters are applied, records are displayed according to those filters (other records are hidden).  Now, when checking the header check box, it only selects records that are part of current page.  For example, if I am on first page and apply filter on one column, grid will hide all rows from the first page that do not match the filter and pull records from 2nd and 3rd pages that match the criteria and show on the first page.  But if I select check box in the header, then only records from first page are selected, records that came from 2nd and 3rd page are not selected.


    Kindly help.


  2. Betsy Lipschutz
    Betsy Lipschutz avatar
    4 posts
    Member since:
    Jul 2019

    Posted 25 May 2020 in reply to Betsy Lipschutz Link to this post


    I found solution to get only the filtered rows using the "Dataview.Indexer.Items" on the MasterTemplate of RadGridView.

    Also, I handled the "HeaderCellToggleStateChanged" event (when header checkbox is checked/unchecked) and looped through all the filtered rows to manually set the checkboxes in rows according to "Header checkbox value".

    Following is the code:

    Private Sub RadGridView1_HeaderCellToggleStateChanged(ByVal sender As Object, ByVal e As GridViewHeaderCellEventArgs)

            Dim dataView As Telerik.WinControls.UI.GridDataView = TryCast(Me.RadGridView1.MasterTemplate.DataView, GridDataView)
            For Each row As GridViewRowInfo In dataView.Indexer.Items
                row.Cells(0).Value = Convert.ToBoolean(e.State)

        End Sub


    Now, the only problem remains is:

    1. Header checkbox, when clicked first time, it checks all the data rows but header check box remains unchecked (incorrect behavior.

    2. When clicked 2nd time, it gets checked and all data rows are also checked (correct behavior.

    3. When clicked 3rd time, it gets unchecked and all data rows are also unchecked (correct behavior)

    Subsequent clicks follows steps 1 to 3 on each click.


    How can I get rid of the 1st step?  (i.e. Header check box remains unchecked and all data rows get checked).


  3. Nadya
    Nadya avatar
    482 posts

    Posted 26 May 2020 Link to this post

    Hello Betsy,

    According to the provided information, it seems that you have enabled paging in your grid. I would like to note that RadGridView exposes two collections that contain data rows:

    -Rows - contains all data rows that belong to RadGridView. Data operations such as grouping, sorting, filtering, etc. do not change the content of the collection or the order in which the row objects exist in the collection.

    -ChildRows - returns the data rows that are currently represented by RadGridView in the order in which they appear. The collection is modified every time a data operation (grouping, sorting, filtering) occurs.

    Similar to filtering, sorting, and grouping, the ChildRows collection is affected by the paging as well and it contains only the records on the current page. More information on this topic you can find here:

    On the other hand the CheckFilteredRows property indicates whether the hidden rows should be checked by the header checkbox. If you have filtering operation, setting CheckFilteredRows to false it will not mark the hidden rows as checked when the applied filter is removed. And it will work fine in this case. 

    I tested the described scenario with both cases that you described on my end and I confirm there is an issue with the header checkbox. This is why I have logged it in our feedback portal by creating a public thread on your behalf. You can track its progress, subscribe for status changes, and add your comments on the following link - feedback item.

    I have also updated your Telerik Points.

    Following the information in the second post, it seems that you managed to found out a suitable workaround for this but then you have a problem when checking the header checkbox for the first time. In addition I can suggest setting the GridViewCheckBoxColumn.ShouldCheckDataRows to false. Please refer to the attached gif file to see the result on my end.

    I have attached my test project as well. Could you please refer to it and see how it works?

    I hope this helps. If you have other questions please let me know.

    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top