--- title: "How to: Navigate Data" ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "cursors [Windows Forms], data sources" - "data sources [Windows Forms], Windows Forms" - "Windows Forms, navigating" - "CurrencyManager class [Windows Forms], navigating Windows Forms data" - "data [Windows Forms], navigating" ms.assetid: 97360f7b-b181-4084-966a-4c62518f735b --- # How to: Navigate Data in Windows Forms In a Windows application, the easiest way to navigate through records in a data source is to bind a component to the data source and then bind controls to the . You can then use the built-in navigation method on the such a , , and . Using these methods will adjust the and properties of the appropriately. You can also find an item and set it as the current item by setting the property. ### To increment the position in a data source 1. Set the property of the for your bound data to the record position to go to. The following example illustrates using the method of the to increment the property when the `nextButton` is clicked. The is associated with the `Customers` table of a dataset `Northwind`. > [!NOTE] > Setting the property to a value beyond the first or last record does not result in an error, as the .NET Framework will not allow you to set the position to a value outside the bounds of the list. If it is important in your application to know whether you have gone past the first or last record, include logic to test whether you will exceed the data element count. [!code-csharp[System.Windows.Forms.NavigatingData#4](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.NavigatingData/CS/Form1.cs#4)] [!code-vb[System.Windows.Forms.NavigatingData#4](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.NavigatingData/VB/Form1.vb#4)] ### To check whether you have passed the end or beginning 1. Create an event handler for the event. In the handler, you can test whether the proposed position value has exceeded the actual data element count. The following example illustrates how you can test whether you have reached the last data element. In the example, if you are at the last element, the **Next** button on the form is disabled. > [!NOTE] > Be aware that, should you change the list you are navigating in code, you should re-enable the **Next** button, so that users may browse the entire length of the new list. Additionally, be aware that the above event for the specific you are working with needs to be associated with its event-handling method. The following is an example of a method for handling the event: [!code-csharp[System.Windows.Forms.NavigatingData#3](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.NavigatingData/CS/Form1.cs#3)] [!code-vb[System.Windows.Forms.NavigatingData#3](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.NavigatingData/VB/Form1.vb#3)] ### To find an item and set it as the current item 1. Find the record you wish to set as the current item. You can do this using the method of the , if your data source implements . Some examples of data sources that implement are and . [!code-csharp[System.Windows.Forms.NavigatingData#2](~/samples/snippets/csharp/VS_Snippets_Winforms/System.Windows.Forms.NavigatingData/CS/Form1.cs#2)] [!code-vb[System.Windows.Forms.NavigatingData#2](~/samples/snippets/visualbasic/VS_Snippets_Winforms/System.Windows.Forms.NavigatingData/VB/Form1.vb#2)] ## See also - [Data Sources Supported by Windows Forms](data-sources-supported-by-windows-forms.md) - [Change Notification in Windows Forms Data Binding](change-notification-in-windows-forms-data-binding.md) - [Data Binding and Windows Forms](data-binding-and-windows-forms.md) - [Windows Forms Data Binding](windows-forms-data-binding.md)