Answered by:
Binding Navigator Controls are not working properly

Question
-
Hi All
I have been trawling the Internet for an answer to this, but cannot find it.
I am using Visual Basic Express 2010.
I have programmatically set up a Datagrid and binding navigator etc., but I cannot get the movenext, movelast buttons to actually hook up to the Data on the Datagrid.
I have tried to set up an addhandler for the BindingNavigatorMoveLastcontrol, and although I can get the BindingNavigatorMoveLastcontrol to display my messagebox WHICH IT DISPLAYS TWICE FOR SOME REASON I cannot get it to actually move around the Dataset, or any of the other navigation properties for that matter. What else do I need to do? Can anyone help please?
Thanks in advance
Wednesday61
Imports System.Data.SqlClient Imports System.Windows.Forms Imports System.Drawing Imports System.ComponentModel Imports System.Collections.Generic Public Class Form1 Inherits Form Private Datagridview1 As New DataGridView Private InstructorsBS As New BindingSource() Private InstructorsBindingNavigator As New BindingNavigator(True) 'Public BindingNavigatorMoveFirstItem As New ToolStripButton Public BindingNavigatorMoveLastItem As New ToolStripButton 'Public BindingNavigatorMovePreviousItem As New ToolStripButton 'Public BindingNavigatorMoveNextItem As New ToolStripButton 'Public BindingNavigatorSaveItem As New ToolStripButton 'Public BindingNavigatorPositionItem As New ToolStripTextBox 'Public BindingNavigatorCountItem As New ToolStripLabel 'Public BindingNavigatorSeparator1 As New ToolStripSeparator 'Public BindingNavigatorSeparator2 As New ToolStripSeparator 'Public BindingNavigatorDeleteItem As New ToolStripButton 'Public BindingNavigatorAddNewItem As New ToolStripButton Public Sub New() Me.InstructorsBindingNavigator.Dock = DockStyle.Top Me.Controls.Add(Me.InstructorsBindingNavigator) Me.Controls.Add(Datagridview1) With Datagridview1 .Location = New Point(50, 50) .Size = New Size(300, 350) End With Me.Size = New Size(500, 200) AddHandler Me.Load, AddressOf Form1_Load InitializeComponent() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim MyConnStringStudents As String = _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\vb08sbs\Chap18\Students.mdb" ' Dim MyConnStringPubs As New SqlConnection _ '("Data Source= .\sqlexpress;AttachDbFilename =C:\sql server 2000 Sample Databases\Pubs.mdf;Integrated Security= true;connect timeout = 30;user instance = true") Dim myConnectionOLE As New OleDb.OleDbConnection(MyConnStringStudents) myConnectionOLE.Open() Dim Studentsadaptor As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter( _ "SELECT * FROM Instructors", MyConnStringStudents) Dim Test As DataSet = New DataSet("Test") Dim Instructors As DataTable = _ Test.Tables.Add("TestInstructors") Studentsadaptor.Fill(Test, "Instructors") Me.BindingNavigatorMoveLastItem = InstructorsBindingNavigator.MoveLastItem With Me.BindingNavigatorMoveLastItem AddHandler BindingNavigatorMoveLastItem.Click, New System.EventHandler(AddressOf bindingnavigatormovelastitem_click) End With Me.Datagridview1.DataSource = Test.Tables("Instructors").DefaultView Me.InstructorsBS.DataSource = Test.Tables("Instructors") Me.InstructorsBindingNavigator.BindingSource = Me.InstructorsBS Sub bindingnavigatormovelastitem_click(ByVal sender As System.Object, ByVal e As System.EventArgs) MsgBox("Test") 'Me.InstructorsBS.MoveLast() 'This is obviously incorrect. I do not know what the code should be!!! End Sub End Class
Wednesday, March 23, 2011 12:27 PM
Answers
-
you have to bind the table to the bindingsource, and the bindingsource and the gridview to the navigator;
Me.InstructorsBS.DataSource = Test.Tables("Instructors")
Me.Datagridview1.DataSource = InstructorsBSMe.InstructorsBindingNavigator.BindingSource = InstructorsBS
- Proposed as answer by Cor Ligthert Wednesday, March 23, 2011 1:00 PM
- Marked as answer by Kee Poppy Wednesday, March 30, 2011 3:28 AM
Wednesday, March 23, 2011 12:43 PM
All replies
-
you have to bind the table to the bindingsource, and the bindingsource and the gridview to the navigator;
Me.InstructorsBS.DataSource = Test.Tables("Instructors")
Me.Datagridview1.DataSource = InstructorsBSMe.InstructorsBindingNavigator.BindingSource = InstructorsBS
- Proposed as answer by Cor Ligthert Wednesday, March 23, 2011 1:00 PM
- Marked as answer by Kee Poppy Wednesday, March 30, 2011 3:28 AM
Wednesday, March 23, 2011 12:43 PM -
Hi Nico
Thank you so much. It works!! I thought I had tried every combination, but obviously not.
I have spent a lot of time on this, so I am very grateful.
Regards
Wednesday61
Wednesday, March 23, 2011 12:53 PM -
you have to bind the table to the bindingsource, and the bindingsource and the gridview to the navigator;
Me.InstructorsBS.DataSource = Test.Tables("Instructors")
Me.Datagridview1.DataSource = InstructorsBSMe.InstructorsBindingNavigator.BindingSource = InstructorsBS
Just to remind you DataGridView, a GridView is an ASP.Net control which cannot be used with a bindingsource
Success
CorWednesday, March 23, 2011 1:01 PM -
Hi Cor
Thank you for your reply.
Nico had already provided the same solution. Sorry I am new to this site, so apologies for the late thank you.
I have just asked for help again, as I am still having problems with Binding Navigator control.
I am very much at the learning stage!
Regards
Wednesday61
Friday, March 25, 2011 10:18 AM