Dynamic page size according with gridview height

1 posts, 0 answers
  1. Wenrong
    Wenrong avatar
    36 posts
    Member since:
    May 2012

    Posted 05 Dec 2012 Link to this post

    I would like to have the gridview paging size dynamically adjusted when gridview height changed, so that the grid would not have any void, nor would user require to scroll up and down.

    I handled the gridview's SizeChanged event and tried the following code:

    private void ItemsList_SizeChanged(object sender, SizeChangedEventArgs e)
        if (e.HeightChanged && ItemsList.ActualHeight > 0)
            var pageSize = (int)(ItemsList.ActualHeight / ItemsList.RowHeight);
            if (ItemsList.ShowColumnHeaders)
            if(pageSize > 0)
                ItemPager.PageSize = pageSize;

    It pretty much worked, except when the column header is visible, as it the taller than the row height, the above calculation is not exact anymore. It also doesn't handle when horizontal scrollbar is visible.

    Is there a better way to calculate the number of rows that should be visible?
Back to Top