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 |
|
|
0e5d4f34-bc9b-47cf-9b8d-93acbb1f1dbb |
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.
-
Add a xref:System.Windows.Forms.BindingSource component named
bindingSource1
and two xref:System.Windows.Forms.TextBox controls namedtextBox1
andtextBox2
. -
Bind
bindingSource1
to data, and the textbox controls tobindingSource1
. To do this, paste the following code into your form and callLoadData
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]
-
Add a xref:System.Windows.Forms.BindingNavigator control named
bindingNavigator1
to your form. -
Set the xref:System.Windows.Forms.BindingNavigator.BindingSource%2A property for
bindingNavigator1
tobindingSource1
. You can do this with the designer or in code.[!code-csharpSystem.Windows.Forms.BindingNavigatorNavigate#3] [!code-vbSystem.Windows.Forms.BindingNavigatorNavigate#3]
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]
This example requires:
- References to the System, System.Data, System.Drawing, System.Windows.Forms and System.Xml assemblies.
- xref:System.Windows.Forms.BindingNavigator
- BindingNavigator Control
- ToolStrip Control