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:
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?
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?