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

RadGridView.Items.PageChanged event does not fire

2 Answers 125 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mark Newman
Top achievements
Rank 1
Mark Newman asked on 15 Nov 2012, 12:26 PM
Hi,

I'm using a RadGridView and RadDataPager together:
<telerik:RadGridView Margin="0,0,0,0"
              Name="grdGeneralPayments"
              SelectionMode="Extended"
              ShowGroupPanel="False"
              ShowColumnFooters="False"    
              CanUserSelect="False"
              CanUserInsertRows="False"
              CanUserDeleteRows="False"
              IsSynchronizedWithCurrentItem ="False"
              MouseDoubleClick="grdGeneralPayments_MouseDoubleClick"
              SelectionChanged="grdGeneralPayments_SelectionChanged"
              Filtering="grdGeneralPayments_Filtering"
              Filtered="grdGeneralPayments_Filtered"
              ScrollViewer.VerticalScrollBarVisibility="Auto"
              ScrollViewer.HorizontalScrollBarVisibility="Auto"
              DockPanel.Dock="Top">
</telerik:RadGridView>
<telerik:RadDataPager Name="radDataPager" Margin="0,0,0,0" DockPanel.Dock="Bottom" PageSize="10" Source="{Binding Items, ElementName=grdGeneralPayments}"
                          PageIndexChanging="radDataPager_PageIndexChanging" />


The grid also has a checkbox select column.
//Because grid columns are auto generated we need to add the select row checkbox column ourselves.
GridViewSelectColumn selectCol = new GridViewSelectColumn();
selectCol.Name = "Select";
//Put select row checkbox column on LHS of the grid.
this.grdGeneralPayments.Columns.Insert(0, selectCol);


Desired behaviour:
The user selects a number of items on one page.
User navigates to another page.
User navigates back to previous page and the previously selected items are still shown as selected.

The following code was working using Telerik.Windows.Controls.GridView.dll version 2010.1.422.35:
public ApproveGeneralPayments()
{
    InitializeComponent();
    this.grdGeneralPayments.Items.PageChanged += new EventHandler<EventArgs>(Items_PageChanged);
}
       
private void Items_PageChanged(object sender, EventArgs e)
{
      this.SelectGloballySelectedItems();
      this.changingPage = false;
}


Since upgrading to Telerik.Windows.Controls.GridView.dll version 2012.2.607.40, the above event "Items_PageChanged" fails to fire.

NB. The method "SelectGloballySelectedItems" compares the items on the currently displayed page with those which have been previously  selected across multiple pages and reselects them.

Any idea why the event isn't firing or is there a new way to achieve the desired functionality.

Thanks,
Mark

2 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 15 Nov 2012, 12:29 PM
Hello,

Can you try using RadDataPager's PageChanging and PageChanged events?
 
Regards,
Rossen Hristov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Mark Newman
Top achievements
Rank 1
answered on 15 Nov 2012, 03:27 PM
Hi,

Thanks for the quick reply.

The RadDataPager doesn't appear to have PageChanging and PageChanged events; it does have PageIndexChanging and PageIndexChanged events.
Unless I'm looking in the wrong place! NB. This is a WPF issue.

My issue was letting the grid SelectionChanged event know that the new page of items had finished loading so my global selection collection didn't get duplicates or get any unexpected deletions.

To be honest I've just managed to resolve the issue by using a combination of the RadDataPager PageIndexChanging event and the RadGridView RowLoaded event.
private void grdGeneralPayments_RowLoaded(object sender, RowLoadedEventArgs e)
{
    this.currentRow++;
    var item = e.Row;
    if (this.globalSelectedItems.Contains(((Telerik.Windows.Controls.RadRowItem)(item)).Item))
    {
        this.grdGeneralPayments.SelectedItems.Add(((Telerik.Windows.Controls.RadRowItem)(item)).Item);
    }
 
    if (this.currentRow % this.radDataPager.PageSize == 0 || (this.generalPayments != null && (this.rowCounter + this.currentRow) == this.generalPayments.Length))
    {
        this.changingPage = false;
    }
}
 
private void radDataPager_PageIndexChanging(object sender, PageIndexChangingEventArgs e)
{
    this.rowCounter = e.NewPageIndex > e.OldPageIndex ? this.rowCounter += this.radDataPager.PageSize : this.rowCounter -= this.radDataPager.PageSize;
    this.changingPage = true;
    this.currentRow = 0;
}
 
private void grdGeneralPayments_SelectionChanged(object sender, SelectionChangeEventArgs e)
{
    if (this.updatingselection || this.changingPage)
    {
        return;
    }
 
    foreach (var item in e.AddedItems)
    {
        this.globalSelectedItems.Add(item);
    }
 
    foreach (var item in e.RemovedItems)
    {
        this.globalSelectedItems.Remove(item);
    }
}

My solution is a bit hacky but it seems to do the trick.

Thanks,
Mark

Tags
GridView
Asked by
Mark Newman
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Mark Newman
Top achievements
Rank 1
Share this question
or