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

Dynamic page size according with gridview height

0 Answers 100 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Wenrong
Top achievements
Rank 1
Wenrong asked on 05 Dec 2012, 11:36 PM
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)
            pageSize--;
        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?

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Wenrong
Top achievements
Rank 1
Share this question
or