Skip to content

Commit e8dd1f4

Browse files
Update README.md
1 parent c4949d0 commit e8dd1f4

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

README.md

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
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?
22

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).
44

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#
68

79
```c#
810
public partial class Form1 : Form
@@ -49,3 +51,49 @@ public partial class Form1 : Form
4951
this.sfDataPager1.Refresh();
5052
}
5153
```
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

Comments
 (0)