Files
docs-desktop/dotnet-desktop-guide/framework/wpf/data/how-to-navigate-through-the-objects-in-a-data-collectionview.md
T
Andy (Steve) De George e9fcf43083 Merge pull request #1135 from dotnet/adegeo-links
Correct .NET Framework links that pointed to old .NET 5 URLs
2021-08-11 12:04:34 -07:00

33 lines
2.3 KiB
Markdown

---
title: "How to: Navigate Through the Objects in a Data CollectionView"
ms.date: "03/30/2017"
dev_langs:
- "csharp"
- "vb"
helpviewer_keywords:
- "CollectionView [WPF], navigating through objects"
- "data binding [WPF], navigating through objects in data CollectionView"
- "navigating through objects in data CollectionView [WPF]"
ms.assetid: fcd37590-bce1-4ac9-8b74-3b96c7458b8a
---
# How to: Navigate Through the Objects in a Data CollectionView
Views allow the same data collection to be viewed in different ways, depending on sorting, filtering, or grouping. Views also provide a current record pointer concept and enable moving the pointer. This example shows how to get the current object as well as navigate through the objects in a data collection using the functionality provided in the <xref:System.Windows.Data.CollectionView> class.
## Example
In this example, `myCollectionView` is a <xref:System.Windows.Data.CollectionView> object that is a view over a bound collection.
In the following example, `OnButton` is an event handler for the `Previous` and `Next` buttons in an application, which are buttons that allow the user to navigate the data collection. Note that the <xref:System.Windows.Data.CollectionView.IsCurrentBeforeFirst%2A> and <xref:System.Windows.Data.CollectionView.IsCurrentAfterLast%2A> properties report whether the current record pointer has come to the beginning and the end of the list respectively so that <xref:System.Windows.Data.CollectionView.MoveCurrentToFirst%2A> and <xref:System.Windows.Data.CollectionView.MoveCurrentToLast%2A> can be called as appropriately.
The <xref:System.Windows.Data.CollectionView.CurrentItem%2A> property of the view is cast as an `Order` to return the current order item in the collection.
[!code-csharp[CollectionView#OnButton](~/samples/snippets/csharp/VS_Snippets_Wpf/CollectionView/CSharp/Page1.xaml.cs#onbutton)]
[!code-vb[CollectionView#OnButton](~/samples/snippets/visualbasic/VS_Snippets_Wpf/CollectionView/VisualBasic/Page1.xaml.vb#onbutton)]
## See also
- [Data Binding Overview](data-binding-overview.md)
- [Sort Data in a View](how-to-sort-data-in-a-view.md)
- [Filter Data in a View](how-to-filter-data-in-a-view.md)
- [Sort and Group Data Using a View in XAML](how-to-sort-and-group-data-using-a-view-in-xaml.md)
- [How-to Topics](data-binding-how-to-topics.md)