I'm upgrading my telerik version, I need to find the index of the first visible row. I used to do this:
this.ItemsControl.VirtualizingPanel.FirstVisibleChildIndex;
But this code no longer compiles, and I can't find an alternative. Does this functionality still exists in the newer versions of the product?
7 Answers, 1 is accepted
0
Hello Gary,
While improving the performance of RadGridView scrolling we have generally refactored the Virtualizing panel . Unfortunately the property mentioned no longer exists.
Please share in what scenario you need this , so we can try find a workaround with the curent API of RadGridView. More details on the final goal may help me provide a "close-to-real" sample for you.
Best wishes,
Pavel Pavlov
the Telerik team
While improving the performance of RadGridView scrolling we have generally refactored the Virtualizing panel . Unfortunately the property mentioned no longer exists.
Please share in what scenario you need this , so we can try find a workaround with the curent API of RadGridView. More details on the final goal may help me provide a "close-to-real" sample for you.
Best wishes,
Pavel Pavlov
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Gary
Top achievements
Rank 1
answered on 07 Jul 2010, 06:23 PM
Our product is an IDE which people use to develop windows applications with. One of the controls we make available is a grid. This product has been around for decades, and we're now supporting a WPF build option, and using the telerik grid control. The language our IDE uses also has a rich API to interact with the grid. One such API allows the user to query the "visible range" of the grid, i.e. what's the first row number visible, and what's the last.
So to support that API call I was using the FirstVisibleChildIndex. I was also using several other properties which I'm not seeing any more. Basically, what I need is:
- The first visible row index
- The last visible row index
With the older version I was using FirstVisibleChildIndex for the first requirement, then I would get the view port height, and use the row height of the view port to find the last row index. So I need replacements for these three properties:
this.ItemsControl.VirtualizingPanel.FirstVisibleChildIndex;
this.ItemsControl.VirtualizingPanel.RowHeight;
this.ItemsControl.VirtualizingPanel.ViewportHeight
0
Hello Gary,
You may try using the extension method ChildrenOfType<>.
Something like :
Hope that helps.
Sincerely yours,
Pavel Pavlov
the Telerik team
You may try using the extension method ChildrenOfType<>.
Something like :
RadGridView.ChildrenOfType<GridViewRow>();
his will return a collection of the rows visible at the moment .
Hope that helps.
Sincerely yours,
Pavel Pavlov
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Gary
Top achievements
Rank 1
answered on 09 Jul 2010, 05:27 PM
I tried your suggestion, so I wrote this code:
But it looks like ChildrenOfType does not return a list that is ordered, so the first item in the list is not actually going to be the first visible item viewable in the grid.
public
int
FirstVisibileRowIdx
{
get
{
IList<GridViewRow> visibleRows =
this
.ChildrenOfType<GridViewRow>();
if
(visibleRows ==
null
|| visibleRows.Count < 2)
{
return
0;
}
//first item in list is the "new row" item
return
this
.Items.IndexOf(visibleRows[1].Item);
}
}
But it looks like ChildrenOfType does not return a list that is ordered, so the first item in the list is not actually going to be the first visible item viewable in the grid.
0
Hi Gary,
Regards,
Milan
the Telerik team
I have prepared a sample solution which demonstrates how you can get the first and the last visible items.
Hope it works.
Regards,
Milan
the Telerik team
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 Public Issue Tracking
system and vote to affect the priority of the items
0
Rahul
Top achievements
Rank 1
answered on 21 Mar 2014, 10:52 AM
Hii,
We have a simillar requirement in our project where we need to know the first and last dataobjects shown in the Rad Grid View.
And Its really nice to see this thread in your forumns.
Exactly our Requirement is:
--------------------------------------
We have a data of 10000 records and we firstly show the data of first 10 records in the grid for example. But along with all those 10 Fully filled records, we also populate the grid with Other Remaining data object which are not fully filled. Our objective is that When the user scrolls down or moves the scroll to some position down, we want to identify the First And Last row and then based on the PrimaryKey Ids of those objects, we want to do some custom logic and then fetch data for next records and proceed.
A
Finally we are looking into the above attached solution provided by Telerik (gridfirstlastvisible.zip). It seems to be good but I would like to bring forward few Observations/limitations of your solution:
1) I see there is a hard coded value in the below code segment:
MainWindow.xaml.cs -> GetLastvisibleIndexFromScrollViewer
var bottomPoint = new Point(1, this.gridScrollViewer.ViewportHeight - 10);
There is a value 10 harcoded in the above line of code. Can you please tel me in detail what exactly is that value and why it is being subtracted.
And why it is harcoded as 10.
If I have to use the code, what should be the thing I need to do dynamically for retrieving that value dynamically
I didnot get the real usage of that.
2) Your piece of code fails when we do changes in the XAML file.
For Example:
Just add margin to the grid (<Grid Margin="15") as "Margin="15"", now resize the window where you can see only 4-5 records. Now click on the button.
The application gets crashed. Attached the crash image.
Not only that, even if you add a text box above the grid by adding a new row, It will crash the application.
I Dont understand whats the relation between the Margin or adding a new element on the top of the Grid.
My conclusion is that the Grids Scroll Viewer is some how tightly couple with the margin of it from the top window position.
please let me know what and how handle this.
It will be really great if you can provide the sample application for me.
We have a simillar requirement in our project where we need to know the first and last dataobjects shown in the Rad Grid View.
And Its really nice to see this thread in your forumns.
Exactly our Requirement is:
--------------------------------------
We have a data of 10000 records and we firstly show the data of first 10 records in the grid for example. But along with all those 10 Fully filled records, we also populate the grid with Other Remaining data object which are not fully filled. Our objective is that When the user scrolls down or moves the scroll to some position down, we want to identify the First And Last row and then based on the PrimaryKey Ids of those objects, we want to do some custom logic and then fetch data for next records and proceed.
A
Finally we are looking into the above attached solution provided by Telerik (gridfirstlastvisible.zip). It seems to be good but I would like to bring forward few Observations/limitations of your solution:
1) I see there is a hard coded value in the below code segment:
MainWindow.xaml.cs -> GetLastvisibleIndexFromScrollViewer
var bottomPoint = new Point(1, this.gridScrollViewer.ViewportHeight - 10);
There is a value 10 harcoded in the above line of code. Can you please tel me in detail what exactly is that value and why it is being subtracted.
And why it is harcoded as 10.
If I have to use the code, what should be the thing I need to do dynamically for retrieving that value dynamically
I didnot get the real usage of that.
2) Your piece of code fails when we do changes in the XAML file.
For Example:
Just add margin to the grid (<Grid Margin="15") as "Margin="15"", now resize the window where you can see only 4-5 records. Now click on the button.
The application gets crashed. Attached the crash image.
Not only that, even if you add a text box above the grid by adding a new row, It will crash the application.
I Dont understand whats the relation between the Margin or adding a new element on the top of the Grid.
My conclusion is that the Grids Scroll Viewer is some how tightly couple with the margin of it from the top window position.
please let me know what and how handle this.
It will be really great if you can provide the sample application for me.
0
Hello Rahul,
I am afraid there is no easy way to find the exact number of GridViewRows displayed into view. The solution we have suggested in this forum is kind of a "hack".
For your purposes I can suggest finding the rows with the ChildrenOfType extension method. That way the currently created visual elements of type GridViewRow will be returned. This will also include some elements (generally one or two) that are on the borders of the ViewPort, but I believe this is acceptable based on your requirement.
For example:
I hope you can use this. Let me know how it works for you.
Regards,
Didie
Telerik
I am afraid there is no easy way to find the exact number of GridViewRows displayed into view. The solution we have suggested in this forum is kind of a "hack".
For your purposes I can suggest finding the rows with the ChildrenOfType extension method. That way the currently created visual elements of type GridViewRow will be returned. This will also include some elements (generally one or two) that are on the borders of the ViewPort, but I believe this is acceptable based on your requirement.
For example:
private
int
GetLastVisibleIndexFromAllRealized()
{
var lastRow =
this
.playersGrid.ChildrenOfType<GridViewRow>().LastOrDefault();
if
(lastRow !=
null
)
{
return
this
.playersGrid.Items.IndexOf(lastRow.Item);
}
else
{
return
-1;
}
}
private
int
GetFirstVisibleIndexFromAllRealized()
{
var firstRow =
this
.playersGrid.ChildrenOfType<GridViewRow>().FirstOrDefault();
if
(firstRow !=
null
)
{
return
this
.playersGrid.Items.IndexOf(firstRow.Item);
}
else
{
return
-1;
}
}
I hope you can use this. Let me know how it works for you.
Regards,
Didie
Telerik
Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.