Currently i have the problem, that i need to know how much visible rows are in the grid. For this, i use the following code:
return
this
.ChildrenOfType<GridViewRow>().Where(item => item.IsVisible).Count();
But this always returns more columns (about 2 - 5) than i can really see. So what am i doing wrong?
Thank you very much!
6 Answers, 1 is accepted
0
Hello Benedikt,
The reason behind the inconsistencies of the data is due to the UI virtualization of the RadGridView and the GridViewRow being a visual element. We do not advise on working with such elements on the code behind as it could result in handling wrong information, as in your case. Instead, you should work with the data source collection directly. On the following you can get more information regarding the UI Virtualization.
What could be helpful in your situation is the following forum thread - FirstVisibleChildIndex. Please, check the approach suggested there and consider whether implementing it in your project would work.
If this doesn't fit your needs, please share additional details on your end goal (why you need to know the count of visible rows in the view) and we will try to suggest an alternative solution.
Regards,
Stefan Nenchev
Telerik
The reason behind the inconsistencies of the data is due to the UI virtualization of the RadGridView and the GridViewRow being a visual element. We do not advise on working with such elements on the code behind as it could result in handling wrong information, as in your case. Instead, you should work with the data source collection directly. On the following you can get more information regarding the UI Virtualization.
What could be helpful in your situation is the following forum thread - FirstVisibleChildIndex. Please, check the approach suggested there and consider whether implementing it in your project would work.
If this doesn't fit your needs, please share additional details on your end goal (why you need to know the count of visible rows in the view) and we will try to suggest an alternative solution.
Regards,
Stefan Nenchev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Benedikt
Top achievements
Rank 1
answered on 26 Oct 2015, 02:56 PM
Thank you for your answer. My goal is to implement my own Page-Up and Page-Down functionality, because we need very specific behaviour. For this reason i have to know, how much large is a "page".
0
Benedikt
Top achievements
Rank 1
answered on 26 Oct 2015, 03:08 PM
As an additional informat, your solution with: GetLastVisibleIndexFromAllRealized does not work. I get totally rendom numbers, by using it like this:
public
int
VisibleRowCount
{
get
{
var res = GetLastVisibleIndexFromAllRealized() - GetFirstVisibleIndexFromAllRealized();
if
(res < 0)
{
res = 0;
}
return
res;
}
}
0
Hi Benedikt,
I am sorry to hear that the project from the other forum thread was not relevant in your situation. As advised in the thread itself, this implementation is kind of a hack and was designed to work in just one certain scenario.
After some further investigation from our side, what I can suggest for you is to use the GridViewVirtualizingPanel in order to get the page height. Please refer to the following code snippet:
.
Eventually, you can use it in order to get the number of the visible rows as well:
Please, update me if this information was of help.
Regards,
Stefan Nenchev
Telerik
I am sorry to hear that the project from the other forum thread was not relevant in your situation. As advised in the thread itself, this implementation is kind of a hack and was designed to work in just one certain scenario.
After some further investigation from our side, what I can suggest for you is to use the GridViewVirtualizingPanel in order to get the page height. Please refer to the following code snippet:
var viewportHeight =
this
.radGridView.ChildrenOfType<GridViewVirtualizingPanel>().FirstOrDefault().ViewportHeight;
Eventually, you can use it in order to get the number of the visible rows as well:
var visibleRows = viewportHeight /
this
.radGridView.RowHeight;
Please, update me if this information was of help.
Regards,
Stefan Nenchev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
1
Benedikt
Top achievements
Rank 1
answered on 01 Nov 2015, 05:09 PM
This seems to solve the problem
public
int
VisibleRowCount
{
get
{
int
visibleRows = 0;
var viewportHeight =
this
.ChildrenOfType<GridViewVirtualizingPanel>().FirstOrDefault().ViewportHeight;
double
height = 0;
foreach
(var row
in
this
.ChildrenOfType<GridViewRow>().Where(item => item.IsVisible))
{
height += row.ActualHeight;
if
(height <= viewportHeight)
{
visibleRows++;
}
else
{
break
;
}
}
return
visibleRows;
}
}
0
Hi Benedikt,
I am happy to see that the implementation was useful in your case.
Regards,
Stefan Nenchev
Telerik
I am happy to see that the implementation was useful in your case.
Regards,
Stefan Nenchev
Telerik
Do you want to have your say when we set our development plans?
Do you want to know when a feature you care about is added or when a bug fixed?
Explore the
Telerik Feedback Portal
and vote to affect the priority of the items