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

How to detect currently visible rows

1 Answer 136 Views
Grid for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Freddy
Top achievements
Rank 1
Freddy asked on 20 Jan 2015, 04:07 PM
I'm using a RadDataGrid, and need to find out what rows are currently visible. Does RadDataGrid have an equivalent to "FirstDisplayedScrollingRowIndex" or "VisualRows" or similar?

First, here is some background.

So we have a RadDataGrid that is displaying a list of items. The item information is being updated on the fly and we need the RadDataGrid to update itself to reflect those changes. Another developer also working on the project said from what he could find we would need to set the grid's items to null, and then set them to our updated list in order to get the RadDataGrid to update itself. Like this:

// reset the source of the DataGrid so the DataGrid UI will update itself
this.DataGrid.ItemsSource = null;
this.DataGrid.ItemsSource = ourListOfItems;

Is there a better way to do that?

So because we nulling the ItemsSource and adding a new set of items (which are really just the exact same set of items, they've just been updated), the scrollbars have a problem. If you are scrolled down in the RadDataGrid, when the ItemsSource is reset, the scrollbars also reset, sending you up to the top. So, how can I make it so the scrollbars will go back to the position they were already in? Seemed like one way was to find the currently visible rows before resetting the ItemsSource. So how can I do that?

1 Answer, 1 is accepted

Sort by
0
Tsvyatko
Telerik team
answered on 21 Jan 2015, 12:33 PM
Hello Freddy,

From the information shared I understand that you need to update some of the items in the ItemsSource in real time.

What I can suggest is take advantage of INotifyCollectionChanged interface (e.g. setting ItemsSource to instance of ObservableCollection). Also make sure that you objects implement INotifyPropertyChanged. That way the grid will keep its scroll position. This will also be preferred setup in this scenario when talking to performance.

Alternatively, you can utilize ScrollIndexIntoView or ScrollItemIntoView methods to set the scroll position to the desired offset after the itemsSource is changed.

Let us know if this helps in your scenario.

Regards,
Tsvyatko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid for XAML
Asked by
Freddy
Top achievements
Rank 1
Answers by
Tsvyatko
Telerik team
Share this question
or