Binding Navigator Toolbar Not working

Hi All,

I'm currently working on a project which involves designing a front end GUI in Visual Studio express with the data being provided from the sample Northwind SQL database.

The problem is that I can get the Binding Navigator toolstrip (first/last record, add/delete record etc) to work on only one of my forms while it gives an error if I try and use it with any other form. The forms are the same except the data that they call upon and I have changed the code to take account of that.

When I copy code from the one form that does work and paste it in another, an error comes up under BindingSource and so while the form runs and executes, the toolbar won't work at all.

Any ideas or suggestions about solutions please?

Thanks,

Beeswax

This is the code from the form that does work:

Code Snippet

PrivateSub BindingNavigator1_RefreshItems(ByVal senderAs System.Object,ByVal eAs System.EventArgs)Handles BindingNavigator1.RefreshItems

Me.BindingNavigator1.AddNewItem =Me.BindingNavigatorAddNewItem

Me.BindingNavigator1.BindingSource =Me.BindingSource1

Me.BindingNavigator1.CountItem =Me.BindingNavigatorCountItem

Me.BindingNavigator1.DeleteItem =Me.BindingNavigatorDeleteItem

Me.BindingNavigator1.Items.AddRange(New System.Windows.Forms.ToolStripItem() {Me.BindingNavigatorMoveFirstItem,Me.BindingNavigatorMovePreviousItem,Me.BindingNavigatorSeparator,Me.BindingNavigatorPositionItem,Me.BindingNavigatorCountItem,Me.BindingNavigatorSeparator1,Me.BindingNavigatorMoveNextItem,Me.BindingNavigatorMoveLastItem,Me.BindingNavigatorSeparator2,Me.BindingNavigatorAddNewItem,Me.BindingNavigatorDeleteItem})

Me.BindingNavigator1.Location =New System.Drawing.Point(0, 0)

Me.BindingNavigator1.MoveFirstItem =Me.BindingNavigatorMoveFirstItem

Me.BindingNavigator1.MoveLastItem =Me.BindingNavigatorMoveLastItem

Me.BindingNavigator1.MoveNextItem =Me.BindingNavigatorMoveNextItem

Me.BindingNavigator1.MovePreviousItem =Me.BindingNavigatorMovePreviousItem

Me.BindingNavigator1.Name ="BindingNavigator1"

Me.BindingNavigator1.PositionItem =Me.BindingNavigatorPositionItem

Me.BindingNavigator1.Size =New System.Drawing.Size(545, 25)

Me.BindingNavigator1.TabIndex = 0

Me.BindingNavigator1.Text ="BindingNavigator"

'BindingNavigatorMoveFirstItem

Me.BindingNavigatorMoveFirstItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image

'Me.BindingNavigatorMoveFirstItem.Image = CType(Resources.GetObject("BindingNavigatorMoveFirstItem.Image"), System.Drawing.Image)

Me.BindingNavigatorMoveFirstItem.Name ="BindingNavigatorMoveFirstItem"

Me.BindingNavigatorMoveFirstItem.RightToLeftAutoMirrorImage =True

Me.BindingNavigatorMoveFirstItem.Size =New System.Drawing.Size(23, 22)

Me.BindingNavigatorMoveFirstItem.Text ="Move first"

'

'BindingNavigatorMovePreviousItem

'

Me.BindingNavigatorMovePreviousItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image

'Me.BindingNavigatorMovePreviousItem.Image = CType(Resources.GetObject("BindingNavigatorMovePreviousItem.Image"), System.Drawing.Image)

Me.BindingNavigatorMovePreviousItem.Name ="BindingNavigatorMovePreviousItem"

Me.BindingNavigatorMovePreviousItem.RightToLeftAutoMirrorImage =True

Me.BindingNavigatorMovePreviousItem.Size =New System.Drawing.Size(23, 22)

Me.BindingNavigatorMovePreviousItem.Text ="Move previous"

'

'BindingNavigatorSeparator

'

Me.BindingNavigatorSeparator.Name ="BindingNavigatorSeparator"

Me.BindingNavigatorSeparator.Size =New System.Drawing.Size(6, 25)

'

'BindingNavigatorPositionItem

'

Me.BindingNavigatorPositionItem.AccessibleName ="Position"

Me.BindingNavigatorPositionItem.AutoSize =False

Me.BindingNavigatorPositionItem.Name ="BindingNavigatorPositionItem"

Me.BindingNavigatorPositionItem.Size =New System.Drawing.Size(50, 21)

Me.BindingNavigatorPositionItem.Text ="0"

Me.BindingNavigatorPositionItem.ToolTipText ="Current position"

'

'BindingNavigatorCountItem

'

Me.BindingNavigatorCountItem.Name ="BindingNavigatorCountItem"

Me.BindingNavigatorCountItem.Size =New System.Drawing.Size(36, 13)

Me.BindingNavigatorCountItem.Text ="of {0}"

Me.BindingNavigatorCountItem.ToolTipText ="Total number of items"

'

'BindingNavigatorSeparator1

'

Me.BindingNavigatorSeparator1.Name ="BindingNavigatorSeparator"

Me.BindingNavigatorSeparator1.Size =New System.Drawing.Size(6, 6)

'

'BindingNavigatorMoveNextItem

'

Me.BindingNavigatorMoveNextItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image

'Me.BindingNavigatorMoveNextItem.Image = CType(Resources.GetObject("BindingNavigatorMoveNextItem.Image"), System.Drawing.Image)

Me.BindingNavigatorMoveNextItem.Name ="BindingNavigatorMoveNextItem"

Me.BindingNavigatorMoveNextItem.RightToLeftAutoMirrorImage =True

Me.BindingNavigatorMoveNextItem.Size =New System.Drawing.Size(23, 20)

Me.BindingNavigatorMoveNextItem.Text ="Move next"

'

'BindingNavigatorMoveLastItem

'

Me.BindingNavigatorMoveLastItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image

'Me.BindingNavigatorMoveLastItem.Image = CType(Resources("BindingNavigatorMoveLastItem.Image"), System.Drawing.Image)

Me.BindingNavigatorMoveLastItem.Name ="BindingNavigatorMoveLastItem"

Me.BindingNavigatorMoveLastItem.RightToLeftAutoMirrorImage =True

Me.BindingNavigatorMoveLastItem.Size =New System.Drawing.Size(23, 20)

Me.BindingNavigatorMoveLastItem.Text ="Move last"

'

'BindingNavigatorSeparator2

'

Me.BindingNavigatorSeparator2.Name ="BindingNavigatorSeparator"

Me.BindingNavigatorSeparator2.Size =New System.Drawing.Size(6, 6)

'

'BindingNavigatorAddNewItem

'

Me.BindingNavigatorAddNewItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image

'Me.BindingNavigatorAddNewItem.Image = CType(Resources.GetObject("BindingNavigatorAddNewItem.Image"), System.Drawing.Image)

Me.BindingNavigatorAddNewItem.Name ="BindingNavigatorAddNewItem"

Me.BindingNavigatorAddNewItem.RightToLeftAutoMirrorImage =True

Me.BindingNavigatorAddNewItem.Size =New System.Drawing.Size(23, 22)

Me.BindingNavigatorAddNewItem.Text ="Add new"

'

'BindingNavigatorDeleteItem

'

Me.BindingNavigatorDeleteItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image

'Me.BindingNavigatorDeleteItem.Image = CType(Resources.GetObject("BindingNavigatorDeleteItem.Image"), System.Drawing.Image)

Me.BindingNavigatorDeleteItem.Name ="BindingNavigatorDeleteItem"

Me.BindingNavigatorDeleteItem.RightToLeftAutoMirrorImage =True

Me.BindingNavigatorDeleteItem.Size =New System.Drawing.Size(23, 22)

Me.BindingNavigatorDeleteItem.Text ="Delete"

EndSub

[13044 byte] By [beeswax34] at [2008-1-10]
# 1

Hi Beeswax34,

Based on your post, my understanding of your question is that it is about the use of the BingNavigator control.

I would like to recommend you see BindingNavigator Control Overview in MSDN. Here is the code snippet to move through a DataSet with the BindingNavigator control. If you have any further questions, please tell me.

Code Block

Dim ds As New DataSet

Private dt As New DataTable()

Private bs As New BindingSource()

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

dt.Columns.Add("aa")

dt.Columns.Add("bb")

For i As Integer = 0 To 49

dt.Rows.Add("aa" & i, "bb" & i)

Next

dt.AcceptChanges()

ds.Tables.Add(dt)

bs.DataSource = ds

bs.DataMember = ds.Tables(0).TableName

Me.DataGridView1.DataSource = bs

Me.BindingNavigator1.BindingSource = bs

End Sub

Best regards,

Riquel.

RiquelDong–MSFT at 2007-10-3 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2

Hi

Thanks for the reply. My specific question is that can I put 2 different tables into one form and to do that do I need a new SQL connection and new dataset. If so, what extra code do I need to implement that into my project?

Thanks,

Beeswax34

beeswax34 at 2007-10-3 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 3

Hi Beeswax34,

Based on your post, my understanding of your question is that your application needs to populate two datatables. Dose your application fetch data from the same database or the different databases? If your application fetch data from the same database, you can modify the SelectCommand to fetch data from the different data tables. If your application fetch data from the different databases, your application can fetch data into the orignal dataset or a new dataset based on your need. Here is code snippet to fetch data from the different databases and put data into a dataset.

Code Block

Imports System.Data.OleDb

Imports System.Data.SqlClient

Public Class Form1

Dim con As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Northwind.mdb")

Dim sql As OleDbCommand = New OleDbCommand("SELECT * FROM Shippers", con)

Dim ds As DataSet = New DataSet()

Dim DataAdapter1 As OleDbDataAdapter = New OleDbDataAdapter()

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

con.Open()

DataAdapter1.SelectCommand = sql

DataAdapter1.MissingSchemaAction = MissingSchemaAction.AddWithKey

DataAdapter1.Fill(ds, "Shippers")

DataGridView1.DataSource = ds

DataGridView1.DataMember = "Shippers"

con.Close()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim conn As SqlConnection = New SqlConnection("Data Source=servername;Initial Catalog=Northwind;Integrated Security=True")

Dim sel As String = "SELECT ShipperID, CompanyName FROM Shippers"

Dim da As SqlDataAdapter = New SqlDataAdapter(sel, conn)

da.MissingSchemaAction = MissingSchemaAction.AddWithKey

'Dim ds As DataSet = New DataSet()

da.Fill(ds, "Shippers1")

Me.DataGridView1.DataSource = ds

Me.DataGridView1.DataMember = "Shippers1"

End Sub

End Class

Best regards,

Riquel.

RiquelDong–MSFT at 2007-10-3 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 4

Hi Riquel,

Thanks a lot for your answers. I meant getting from different tables in the same database as opposed to datat from completely indepedent databases. How would I modify your code to reflect that?

Thanks once again,

Beeswax34

beeswax34 at 2007-10-3 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 5

Can you explain again exactly what you are trying to do?

Are you trying to control 2 tables with one navigator?

Or are you trying to use a 2 related tables that filter automatically?

And do you want them on 1 form or seperate forms?

Based on your last post if you are trying to put 2 tables on a single form then just drag the 2 tables to the form

Or are you trying to populate the datagridviews from 2 tables with code?

Can you be real specific on what you want

js06 at 2007-10-3 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 6

Hi,

We don't have a datagridview but we have textboxes instead of gridviews. We want to take data from the databases (single database) and bind it to those textboxes however how can we bind 2 different tables from the same database into different textboxes in one form.

For eg, we have a orders form in which the textboxes display data from the Orders table in the database. We would like to also show the shippers information for each order on the same form. We can get the orders part working but not shippers. We need to set up a relationship between orders and shippers so each reflects a move in position of another

Also how can we get the binding navigator working without having a binding source so again a change in orders would relfect in the shippers datas as well.

Thanks,

Beeswax34

PS ( the code that riquel gave does not work at all)

beeswax34 at 2007-10-3 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 7

First thing i would suggest is to watch the forms over data series from beth massi.

The last part i am a little confused on because if you want a binding navigator but you don't want a binding source then that doesn't quite make sense. Maybe i am not understanding that part right.

If you relate your tables with a foreign key relation then you will automatically be setup to have automatic filtering.

In your explorer you will see the orders table and when you expand it, at the bottom you will see the shippers table

you can drag individual columns to the form from each table. I'm sure it works that same way as with the datagridview where when you select the order it will automatically get the shippers info for that order.

Another thing that i am confused about with this is that if you have an order in 1 table and the shippers info in another table then are you going to have multiple shippers info for each order? The reason i ask this is because if the order will just have 1 shipper then why would you need that in a seperate table?

Either way if you need multiple shipper records for each order then you will have to setup another navigator just for the shippers table. If you look at the properties of the navigator for the orders then that will show you how to setup the navigator for the shippers

js06 at 2007-10-3 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...