Multiple BindingNavigators on Same Windows Form VB 2005
description Article and source code that explain how to use multiple Widows Forms BindingNavigators on the same Windows form with Visual Basic 2005.
get resource -> MultipleBindingNavigatorsonSameWindowsFormVisualBasic2005
environment Visual Studio 2005
language Visual Basic 2005
namespace System.Windows.Forms.BindingNavigator
tags bindingnavigator,binding, datasource,multiple, windows form,visual basic, 2005, vb, .net, visual studio


Use Multiple BindingNavigator Controls on the Same Windows Form

Visual Studio 2005 sometimes automatically adds a BindingNavigator for a BindingSource to a Windows form.

For example, when you drag the first DataSource to a Windows form from the DataSource panel in Visual Studio 2005, a BindingNavigator control is automatically added to the Windows form.

Result

You must sometimes manually add a BindingNavigator for a Windows Forms DataSource. For each additional DataSource you drag to the Windows form, a BindingNavigator is not automatically added.

Result

How to Manually Add a BindingNavigator for an Additional DataSource

From the Toolbox drag a BindingNavigator control to the form.

Results

Right-click the new BindingNavigator in the form components area and select Properties.

In the Properties panel rename BindingNavigator1 to a name that associates it with the BindingSource it will navigate.  In the example it is the EmployeesBindingSource.

In the Properties panel set the DataSource property to the BindingSource the BindingNavigator will navigate. In the example it is the EmployeesBindingSource.

Add code to control how the two BindingNavigator controls interact with the user and the DataGridView controls on the form..  For example, you could add code to hide or show the Navigator controls depending on which DataGrid was last entered.

 

Private Sub CustomersDataGridView_Enter(ByVal sender As Object, ByVal e As System.EventArgs) _

Handles CustomersDataGridView.Enter, EmployeesDataGridView.Enter

    ' Store the name of the DataGridView in a String type variable

    '   named dataGridViewName.

    Dim dataGridViewName As String = CType(sender, Control).Name

 

    ' Hide all BindingNavigator controls.

    Me.CustomersBindingNavigator.Hide()

    Me.EmployeesBindingNavigator.Hide()

 

    ' Show the BindingNavigator control for the DataGridView

    '    just entered.

    Select Case dataGridViewName

        Case "EmployeesDataGridView"

 

            Me.EmployeesBindingNavigator.Show()

        Case "CustomersDataGridView"

            Me.CustomersBindingNavigator.Show()

    End Select

 

End Sub

Note:  When you add an additional BindingNavigator control it will not have have a Save button.  In the example I copied the Save button from the first BindingNavigator control (CustomerBindingNavigator) and pasted it on the second BindingNavigator (EmployeesBindingNavigator) and named the pasted button 'EmployeesBindingNavigatorSaveItem'. Then I added code to handle the new button to the form:

 

Private Sub EmployeesBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EmployeesBindingNavigatorSaveItem.Click

    Me.Validate()

    Me.EmployeesBindingSource.EndEdit()

    Me.EmployeesTableAdapter.Update(Me.NorthwindDataSet.Employees)

End Sub

mike mcintyre http://www.getdotnetcode.com

 

 

 

 

 

 

 

 

 

 

 



Copyright © 2001-2007 aZ Software Developers. All rights reserved.

 

.