Can you use ScrollIntoView () with PagedCollectionView in Silverlight DataGrid?

Is it possible to scroll to a specific row (by object id) in a Silverlight DataGrid that has an ItemsSource , which is a PagedCollectionView .

I upload a list of orders that are grouped by date / status, etc. I need to scroll to a specific order.

  var pcv = new PagedCollectionView(e.Result.Orders); gridOrders.ItemsSource = pcv; 

Unfortunately, ScrollIntoView(order) does not work due to PagedCollectionView .

The MSDN DataGrid article shows that you can go to a group in a PagedCollectionView , but this is not very used.

  foreach (CollectionViewGroup group in pcv.Groups) { dataGrid1.ScrollIntoView(group, null); dataGrid1.CollapseRowGroup(group, true); } 

Is there any way to do this?

+7
silverlight datagrid datagridview
source share
1 answer

Yes, you can scroll through elements in a view when the source of the element is a PagedCollectionView . I am using the group scroll method that you are describing and I am viewing the currently selected item in the view. For this, I have a helper method that the dispatcher uses to invoke the operation as follows:

 private void ScrollCurrentSelectionIntoView() { this.dataGrid.Dispatcher.BeginInvoke(() => { this.dataGrid.ScrollIntoView( this.dataGrid.SelectedItem, this.dataGrid.CurrentColumn); }); } 

I used BeginInvoke , because otherwise the ScrollIntoView call ScrollIntoView not succeed when called directly from the event handler (presumably because the DataGrid did not ScrollIntoView its state for the event being processed). This approach ensures that the current event is correctly processed before the scroll call.

+7
source share

All Articles