We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Setting Page Size Dynamically based on DataGrid size

Thread ID:

Created:

Updated:

Platform:

Replies:

130753 May 31,2017 05:58 AM Jun 3,2017 04:52 AM WPF 1
loading
Tags: SfDataPager
Backer
Asked On May 31, 2017 05:58 AM

Hello,
I like to set the page size based on the DataGrid size, such that no scroll bar appears.

So I set the PageSize to the following values in the Window_Loaded event-handler:
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            for (var tabIndex = MainTabControl.Items.Count - 1; tabIndex >= 0; tabIndex--)
            {
                MainTabControl.SelectedIndex = tabIndex;
                MainTabControl.UpdateLayout();
            }
            dpOrderHistory.PageSize = (int)(dgOrderHistory.ActualHeight / dgOrderHistory.RowHeight);
            dpOrderList.PageSize = (int)(dpOrderList.ActualHeight / dgOrderList.RowHeight);
        }
Here is my XAML-Code:

        <TabControl x:Name="MainTabControl">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <i:InvokeCommandAction Command="{Binding CMDSelectedTabChanged}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <TabItem Header="Bestellliste" >
                <DockPanel>
                    <syncfusion:SfDataPager x:Name="dpOrderList" Source="{Binding TotalProductList}" PageSize="20"   DockPanel.Dock="Bottom"/>
                    <syncfusion:SfDataGrid x:Name="dgOrderList" ItemsSource="{Binding PagedSource, ElementName=dpOrderList}"  SelectionMode="Single" CellTapped="dgOrderList_CellTapped" AutoGeneratingColumn="dgOrderList_AutoGeneratingColumn" AllowSorting="False">

                    </syncfusion:SfDataGrid>
                </DockPanel>
            </TabItem>
            <TabItem Header="Bestellhistorie">
               
                <DockPanel>
                    <syncfusion:SfDataPager x:Name="dpOrderHistory" Source="{Binding TotalOrderStatusList}" PageSize="20"  DockPanel.Dock="Bottom"/>
                    <syncfusion:SfDataGrid x:Name="dgOrderHistory" ItemsSource="{Binding PagedSource, ElementName=dpOrderHistory}"  SelectionMode="Single" CellTapped="dgOrderHistory_CellTapped" AutoGeneratingColumn="dgOrderHistory_AutoGeneratingColumn" AllowSorting="False" >

                    </syncfusion:SfDataGrid>
                </DockPanel>
            </TabItem>
        </TabControl>

If I run the program, the PageSize is still 20. If i do not specify the value in XAML then no rows are displayed in the DataGrid. However I bound a Label to the PageSize value and it displays 34, but the grid shows only 20 items.

How should I change the code such that the grid displays as much items as possible without scrollbars.

Which Event is the right place to compute the PageSize?


Muthukumar Kalyanasundaram [Syncfusion]
Replied On June 3, 2017 04:52 AM

Hi Backer, 
 
Thank you for contacting Syncfusion support. 
 
We have analyzed your provided code. Please find the response from below table. 
 
 
Query 1: 
If I run the program, the PageSize is still 20. If i do not specify the value in XAML then no rows are displayed in the DataGrid. However I bound a Label to the PageSize value and it displays 34, but the grid shows only 20 items. 
 
As per your requirement, we have checked and prepared the sample. For your reference, we have attached the sample in the below location. In the sample, we have loaded the SfDataPager.PageSize based on SfDataGrid  size as shown like below code

Code snippet: 
private void MainWindow_Loaded(object sender, System.Windows.RoutedEventArgs e) 
{ 
    for (var tabIndex = MainTabControl.Items.Count - 1; tabIndex >= 0; tabIndex--) 
    { 
        MainTabControl.SelectedIndex = tabIndex; 
        MainTabControl.UpdateLayout(); 
    } 
    sfDataPager.PageSize = (int)(dataGrid.ActualHeight / dataGrid.RowHeight) - 1; 
    sfDataPager1.PageSize = (int)(dataGrid1.ActualHeight / dataGrid1.RowHeight) - 1; 
    sfDataPager.MoveToFirstPage(); 
    sfDataPager1.MoveToFirstPage(); 
} 
 
 
Query 2: 
How should I change the code such that the grid displays as much items as possible without scrollbars. 
 
Query 3: 
Which Event is the right place to compute the PageSize? 
 
 
There is no event available to calculate the pagesize in datapager. 
 
 
 
Please let us know if you have any query. 
 
Regards, 
Muthukumar K 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;