Skip to content

Latest commit

 

History

History
56 lines (38 loc) · 4.48 KB

how-to-navigate-data-with-the-windows-forms-bindingnavigator-control.md

File metadata and controls

56 lines (38 loc) · 4.48 KB
title description ms.date dev_langs helpviewer_keywords ms.assetid
Navigate Data with BindingNavigator Control
Learn about how to navigate data with the Windows Forms BindingNavigator control, which enables developers to provide end users with a simple data navigation.
03/30/2017
csharp
vb
BindingNavigator control [Windows Forms], navigating data
data [Windows Forms], navigating
data navigation
examples [Windows Forms], BindingNavigator control
0e5d4f34-bc9b-47cf-9b8d-93acbb1f1dbb

How to: Navigate Data with the Windows Forms BindingNavigator Control

The advent of the xref:System.Windows.Forms.BindingNavigator control in Windows Forms enables developers to provide end users with a simple data navigation and manipulation user interface on the forms they create.

The xref:System.Windows.Forms.BindingNavigator control is a xref:System.Windows.Forms.ToolStrip control with buttons preconfigured for navigation to the first, last, next, and previous record in a data set, as well as buttons to add and delete records. Adding buttons to the xref:System.Windows.Forms.BindingNavigator control is easy, because it is a xref:System.Windows.Forms.ToolStrip control. For examples, see How to: Add Load, Save, and Cancel Buttons to the Windows Forms BindingNavigator Control.

For each button on the xref:System.Windows.Forms.BindingNavigator control, there is a corresponding member of the xref:System.Windows.Forms.BindingSource component that programmatically allows the same functionality. For example, the xref:System.Windows.Forms.BindingNavigator.MoveFirstItem%2A button corresponds to the xref:System.Windows.Forms.BindingSource.MoveFirst%2A method of the xref:System.Windows.Forms.BindingSource component, the xref:System.Windows.Forms.BindingNavigator.DeleteItem%2A button corresponds to the xref:System.Windows.Forms.BindingSource.RemoveCurrent%2A method, and so on. As a result, enabling the xref:System.Windows.Forms.BindingNavigator control to navigate data records is a simple as setting its xref:System.Windows.Forms.BindingNavigator.BindingSource%2A property to the appropriate xref:System.Windows.Forms.BindingSource component on the form.

To set up the BindingNavigator control

  1. Add a xref:System.Windows.Forms.BindingSource component named bindingSource1 and two xref:System.Windows.Forms.TextBox controls named textBox1 and textBox2.

  2. Bind bindingSource1 to data, and the textbox controls to bindingSource1. To do this, paste the following code into your form and call LoadData from the form's constructor or xref:System.Windows.Forms.Form.Load event-handling method.

    [!code-csharpSystem.Windows.Forms.BindingNavigatorNavigate#2] [!code-vbSystem.Windows.Forms.BindingNavigatorNavigate#2]

  3. Add a xref:System.Windows.Forms.BindingNavigator control named bindingNavigator1 to your form.

  4. Set the xref:System.Windows.Forms.BindingNavigator.BindingSource%2A property for bindingNavigator1 to bindingSource1. You can do this with the designer or in code.

    [!code-csharpSystem.Windows.Forms.BindingNavigatorNavigate#3] [!code-vbSystem.Windows.Forms.BindingNavigatorNavigate#3]

Example

The following code example is the complete example for the steps listed previously.

[!code-csharpSystem.Windows.Forms.BindingNavigatorNavigate#1] [!code-vbSystem.Windows.Forms.BindingNavigatorNavigate#1]

Compiling the Code

This example requires:

  • References to the System, System.Data, System.Drawing, System.Windows.Forms and System.Xml assemblies.

See also