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

Get notified when visible rows change

3 Answers 222 Views
GridView
This is a migrated thread and some comments may be shown as answers.
BENN
Top achievements
Rank 1
BENN asked on 20 Nov 2012, 06:21 AM
I have this project where the software communicates with a remote hardware.
Based on the visible rows, I need to read only the visible section inside a buffer in the hardware and update the grid accordingly (this is to prevent reading load of irrelevant data which is currently not visible to the user).
There is no easy way of telling what are the visible rows in the GridView (I have read that there was, but now we have to dig in).

I have tried using the method in the example that was given here:
http://www.telerik.com/community/forums/wpf/gridview/firstvisiblechildindex.aspx

However, for some reason in my project it will never find the last row, therefore causing an exception.

I have used a different method of getting all the rows from the virtualizing stack panel and then iterating them to see what is the lowest item index and using the rows count at the num of rows:

        private void recalculateFirstAndLastVisibleIndexes()
        {
            var gvvp = this.radGridView.ChildrenOfType<GridViewVirtualizingPanel>().FirstOrDefault();
 
            if (gvvp == null)
                return;
 
            var rowsList = gvvp.ChildrenOfType<GridViewRow>();
 
            if (rowsList.Any())
            {
                int firstIndex = this.radGridView.Items.IndexOf(rowsList.ElementAt(0).Item);
                foreach (var row in rowsList)
                {
                    firstIndex = Math.Min(firstIndex, this.radGridView.Items.IndexOf(row.Item));
                }
 
                FirstVisibleRowIndex = firstIndex;
                NumOfVisibleRows = rowsList.Count();
            }
            else
            {
                FirstVisibleRowIndex = 0;
                NumOfVisibleRows = 0;
            }
        }



This does work (although it seems to return a little more rows than expected when the scrollviewer is visible....


Still, when the UI starts I try getting the visible rows on several occasions:
radGridView_Loaded
radGridView_DataLoaded
and also: radGridView_ScrollChanged

The problem is that it is not enough...
When I get the DataLoaded event, the rowsList is still empty... I need to wait for the next LayoutUpdated event and only then call the recalculateFirstAndLastVisibleIndexes function.

If I try to rely only on the ScrollChanged event then if there are for example 10 rows and the window are can contain 20 row, then if I add or remove rows then this event is never being called.


I did not find any way to get notified when the visible rows change. Is there any solution?

Thanks.

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 20 Nov 2012, 07:18 AM
Hello,

 It will be better in my opinion if you try our virtual collection instead. Please check this demo for more info:
http://demos.telerik.com/silverlight/#DataVirtualization/FirstLook

You can find the same demo in your local copy of our WPF examples. 

Please check also this help article for more info about data virtualization:
http://www.telerik.com/help/wpf/using-data-virtualization.html 

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
BENN
Top achievements
Rank 1
answered on 20 Nov 2012, 07:32 AM
Ok, but how does it help?

I have a byte array in the model, representing the buffer in the remote hardware server.
the ViewModel has a DataTable which represents the data (since the buffer represents an array of rows).
When data inside the buffer is changed then we know by it's location which cells in the DataTable were altered.

DataTable.DefaultView is connected to the Grid with Binding.
Based on the visible rows we want to update only the visible area in the buffer (and not whole of it each time).

I don't see in any way how I can use the VirtualQueryableCollectionView
0
Vlad
Telerik team
answered on 20 Nov 2012, 07:34 AM
Hi,

You can use virtual collection to request only currently visible data.

Kind regards,
Vlad
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
BENN
Top achievements
Rank 1
Answers by
Vlad
Telerik team
BENN
Top achievements
Rank 1
Share this question
or