GridViewSelectColumn + paging

9 posts, 0 answers
  1. James
    James avatar
    117 posts
    Member since:
    Mar 2009

    Posted 29 Mar 2010 Link to this post

    Hi,

    I'm using a grid, bound to an ienumerable using the standard 'select/deselect all' option:

    <telerikGridView:GridViewSelectColumn UniqueName="columnSelectItem" Width="Auto">
                                                <telerikGridView:GridViewSelectColumn.Header>
                                                    <CheckBox Click="CheckBox_Click" />
                                                </telerikGridView:GridViewSelectColumn.Header>
                                            </telerikGridView:GridViewSelectColumn>

    I'm also using paging as described here: http://demos.telerik.com/silverlight/#GridView/PagingIEnumerable

    Paging works ok, and so does select / deselect all. However, clicking the checkbox in the header to select / deselect all only operates on the items being displayed, not on the whole list. Is this by design? If so, is there a workaround?

    Thanks, James



  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 30 Mar 2010 Link to this post

    Hi James,

    This behavior is expected since the grid only has access to the items that are displayed in the current page. 

    Here is one workaround that might work for your scenario:

    01.BitArray selectedItemsFlags; 
    02.bool selectionRestored = false;
    03.// subscribe for this.myGrid.Items.PageChanging | this.myGrid.Items.PageChanged
    04.  
    05.void Items_PageChanged(object sender, System.EventArgs e)
    06.{
    07.    this.myGrid.SelectedItems.Clear(); 
    08.    this.Dispatcher.BeginInvoke(new System.Action(() => this.RestoreSelectionAfterPageChange()));
    09.}
    10.  
    11.void Items_PageChanging(object sender, System.ComponentModel.PageChangingEventArgs e)
    12.{
    13.    // save current selection
    14.    this.selectedItemsFlags = new BitArray(this.myGrid.Items.PageSize); 
    15.  
    16.    foreach (var item in this.myGrid.SelectedItems) 
    17.    {
    18.        var index = this.myGrid.Items.IndexOf(item); 
    19.        this.selectedItemsFlags[index] = true;
    20.    }
    21.  
    22.    this.selectionRestored = false;
    23.}
    24.  
    25.private void RestoreSelectionAfterPageChange()
    26.{
    27.    if (this.selectedItemsFlags == null || this.selectionRestored)
    28.        return;
    29.  
    30.    // restore selection
    31.    for (int i = 0; i < this.selectedItemsFlags.Count; i++)
    32.    {
    33.        var isSelected = this.selectedItemsFlags[i];
    34.  
    35.        if (isSelected && i < this.myGrid.Items.Count) 
    36.            this.myGrid.SelectedItems.Add(this.myGrid.Items[i]); 
    37.    }
    38.  
    39.    this.selectionRestored = true;
    40.}


    Greetings,
    Milan
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. DevCraft banner
  4. James
    James avatar
    117 posts
    Member since:
    Mar 2009

    Posted 01 Apr 2010 Link to this post

    Hi Milan,

    Thanks for your answer. It looks as though we'll be just as well off having an IsSelected property in our object to bind to a standard column and handle remembering selection there. Is there a simple way of putting a checkbox in the header of a GridViewDataColumn? We can then handle its events ourselves.

    Thanks for your help, James.

    btw, when you check the checkbox on a GridViewSelectColumn and change page, the checkbox stays checked, even though all the records on the next page are unchecked.
  5. James
    James avatar
    117 posts
    Member since:
    Mar 2009

    Posted 02 Apr 2010 Link to this post

    Don't worry - I found how to do it (and then changed back to SelectColumn anyway!)
    Thanks, james.
  6. Claire Kaplan
    Claire Kaplan avatar
    3 posts
    Member since:
    Sep 2009

    Posted 05 Apr 2010 Link to this post

    This is a strange coincidence, but we recently ran into the same kind of problems that you did. Could you summarize how you managed to retain selections across pages? I was tempted to mimic my own gridview select-column but it seems like you were able to overcome most issues with it. Also, how did you ensure the select-all didn't remain checked when you navigate to the next page?

    Thanks,
    -Avinash Chugh
  7. James
    James avatar
    117 posts
    Member since:
    Mar 2009

    Posted 14 Apr 2010 Link to this post

    Hi Claire,

    I'm afraid we never solved the problem of the checkbox remaining checked between pages. We retained selection by having a 'selected' property on the object that we bound to. It was hard work and didn't work perfectly, so we went back to the default method described in this thread using selectcolumns. This isn't perfect either, but it's good enough for now.

    Sorry I can't help more.

    James.
  8. Shreya
    Shreya avatar
    18 posts
    Member since:
    Aug 2014

    Posted 20 Nov 2014 Link to this post

    Hi James and Maya,
    I am facing similar kind of problem. Please Help me in achieving following scenarios:

    1) When Select All suppose I have 186 records and my page size is 10 so I have 19 pages in raddatapager and last one has only 6 records. I have tried implementing the above logic by Maya, when I go to my last page no 19 and then again clicking on any page it shows me only first 6 rows selected not all. 

    2) To capture my selecteditems I have attached a behaviour to grid to get the selected Items in my view model. There I am only getting the first page selected Items
    ((CAManagementViewModel)this.AssociatedObject.DataContext).SelectedVehicles = this.AssociatedObject.SelectedItems;

    3) In the above property of selected Items if user selects different records on different page how to get all maintained in SelectedItems of
    grid.

    Thanks a lot in advance



















  9. James
    James avatar
    117 posts
    Member since:
    Mar 2009

    Posted 20 Nov 2014 in reply to Shreya Link to this post

    Sorry Shreya, it's four years since I looked at this (and other members of the team do more coding on this than me now), and I don't think any knowledge of this remains in my long-term memory!

    Hope you get it sorted...
  10. Shreya
    Shreya avatar
    18 posts
    Member since:
    Aug 2014

    Posted 21 Nov 2014 in reply to Milan Link to this post

    Hi Milan,
    Can you please help me in this...

    I am facing similar kind of problem. Please Help me in achieving following scenarios:

    1) When Select All suppose I have 186 records and my page size is 10 so I have 19 pages in raddatapager and last one has only 6 records. I have tried implementing the above logic by You, when I go to my last page no 19 and then again clicking on any page it shows me only first 6 rows selected not all. 

    2) To capture my selecteditems I have attached a behaviour to grid to get the selected Items in my view model. There I am only getting the first page selected Items
    ((CAManagementViewModel)this.AssociatedObject.DataContext).SelectedVehicles = this.AssociatedObject.SelectedItems;

    3) In the above property of selected Items if user selects different records on different page how to get all maintained in SelectedItems of
    grid.

    Thanks a lot in advance
Back to Top
DevCraft banner