|
1 | | -# How to change the PageCount at runtime when data loaded on demand is filtered in winforms datapager |
| 1 | +# How to Change the PageCount at Runtime When Data Loaded on Demand is Filtered in WinForms DataPager? |
2 | 2 |
|
3 | | -This example illustrates how to change the `PageCount` at runtime when data loaded on demand is filtered in [WinForms DataPager](https://help.syncfusion.com/cr/windowsforms/Syncfusion.WinForms.DataPager.SfDataPager.html). |
| 3 | +This example illustrates how to change the **PageCount** at runtime when data loaded on demand is filtered in [WinForms DataPager](https://help.syncfusion.com/cr/windowsforms/Syncfusion.WinForms.DataPager.SfDataPager.html). |
4 | 4 |
|
5 | | -You can change the [SfDataPager.PageCount](https://help.syncfusion.com/cr/windowsforms/Syncfusion.WinForms.DataPager.SfDataPager.html#Syncfusion_WinForms_DataPager_SfDataPager_PageCount) at runtime based on the records count in on-demand paging. Here, `PageCount` are modified by filtering the records in run time. |
| 5 | +You can change the [SfDataPager.PageCount](https://help.syncfusion.com/cr/windowsforms/Syncfusion.WinForms.DataPager.SfDataPager.html#Syncfusion_WinForms_DataPager_SfDataPager_PageCount) at runtime based on the records count in on-demand paging. Here, **PageCount** are modified by filtering the records in run time. |
| 6 | + |
| 7 | +#### C# |
6 | 8 |
|
7 | 9 | ```c# |
8 | 10 | public partial class Form1 : Form |
@@ -49,3 +51,49 @@ public partial class Form1 : Form |
49 | 51 | this.sfDataPager1.Refresh(); |
50 | 52 | } |
51 | 53 | ``` |
| 54 | + |
| 55 | +#### VB |
| 56 | + |
| 57 | +``` vb |
| 58 | +Partial Public Class Form1 |
| 59 | + Inherits Form |
| 60 | +Private northWind As Northwind |
| 61 | +Private source As New List(Of Orders)() |
| 62 | + |
| 63 | +Public Sub New() |
| 64 | + InitializeComponent() |
| 65 | + Dim connectionString As String = String.Format("Data Source = {0}", ("Northwind.sdf")) |
| 66 | + 'northWind dataProvider connectivity. |
| 67 | + northWind = New Northwind(connectionString) |
| 68 | + source = northWind.Orders.ToList() |
| 69 | + AddHandler Me.sfDataPager1.OnDemandLoading, AddressOf OnDemandLoading |
| 70 | +End Sub |
| 71 | + |
| 72 | +Private Sub OnDemandLoading(ByVal sender As Object, ByVal e As OnDemandLoadingEventArgs) |
| 73 | + sfDataPager1.LoadDynamicData(e.StartRowIndex, source.Skip(e.StartRowIndex).Take(e.PageSize)) |
| 74 | +End Sub |
| 75 | + |
| 76 | +Private Function ApplyFilter(ByVal NorthwindSource As Northwind) As List(Of Orders) |
| 77 | + 'records are filtered based on CustomerID column |
| 78 | + Return NorthwindSource.Orders.Where(Function(item) item.CustomerID.Contains(filterTextBox.Text)).ToList() |
| 79 | +End Function |
| 80 | + |
| 81 | +Private Sub FilterBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) |
| 82 | + source = ApplyFilter(northWind) |
| 83 | + 'page count resets based on filtered records. |
| 84 | + If source.Count() < sfDataPager1.PageSize Then |
| 85 | + Me.sfDataPager1.PageCount = 1 |
| 86 | + Else |
| 87 | + Dim count = source.Count() / sfDataPager1.PageSize |
| 88 | + If source.Count() Mod sfDataPager1.PageSize = 0 Then |
| 89 | + Me.sfDataPager1.PageCount = count |
| 90 | + Else |
| 91 | + Me.sfDataPager1.PageCount = count + 1 |
| 92 | + End If |
| 93 | + End If |
| 94 | + Me.sfDataPager1.MoveToPage(0) |
| 95 | + Me.sfDataPager1.Refresh() |
| 96 | +End Sub |
| 97 | +``` |
| 98 | + |
| 99 | +Here, records are filtered based on the textbox text in clicking event of Filter button. Initially PageCount is 5 and it is changed as 1 once the records are filtered. |
0 commit comments