-
Mar 2nd, 2014, 08:28 AM
#1
Thread Starter
Addicted Member
[RESOLVED] How to create multiple navigators in one form??
I have a staff details form and there are two different tables in it. The tables are Department and Staff Details.
Here is my form.
For the department fields there's a navigator and it only navigates the department code and department name.
here is the code.
Code:
Imports System.Data.OleDb
Public Class Staff_Editor
Dim dbcursor As Integer
Dim inc As Integer
Dim MaxRows As Integer
Dim conn As New OleDb.OleDbConnection
Dim dbProvider As String
Dim dbSource As String
Dim dj As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String = "SELECT * FROM Department"
Private Sub Staff_Editor_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dbProvider = "Provider=Microsoft.ACE.OLEDB.12.0;"
dbSource = "Data Source=|DataDirectory|\Payroll_BackEnd.accdb"
conn.ConnectionString = dbProvider & dbSource
conn.Open()
da = New OleDb.OleDbDataAdapter(sql, conn)
da.Fill(dj, "Payroll_BackEnd")
MaxRows = da.Fill(dj, "Payroll_BackEnd")
DepartmentCodeTextBox1.Enabled = False
DepartmentNameTextBox.Enabled = False
Private Sub NavigateRecords()
DepartmentCodeTextBox1.Text = dj.Tables("Payroll_BackEnd").Rows(inc).Item(0)
DepartmentNameTextBox.Text = dj.Tables("Payroll_BackEnd").Rows(inc).Item(1)
End Sub
Private Sub NextRecordButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NextRecordButton.Click
If inc <> MaxRows - 1 Then
inc = inc + 1
NavigateRecords()
Else
MsgBox("No More Rows")
End If
End Sub
Private Sub PreviousRecordButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PreviousRecordButton.Click
If inc > 0 Then
inc = inc - 1
NavigateRecords()
ElseIf inc = -1 Then
MsgBox("No Records Yet")
ElseIf inc = 0 Then
MsgBox("First Record")
End If
End Sub
Private Sub FirstRecordButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FirstRecordButton.Click
If inc <> 0 Then
MsgBox("This is the First Record")
inc = 0
NavigateRecords()
End If
End Sub
Private Sub LastRecordButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LastRecordButton.Click
If inc <> MaxRows - 1 Then
MsgBox("This is the Last Record")
inc = MaxRows - 1
NavigateRecords()
End If
End Sub
I have used parameters to delete, save, update.
So all i am asking is that if I use binding navigator without using any code will it create any error??
Is it possible to have bindingsource, bindingnavigators and dataset to connect my staff Details form so that i could navigate to records???
-
Mar 2nd, 2014, 09:43 AM
#2
Re: How to create multiple navigators in one form??
Absolutely! That's exactly what a BindingNavigator is for. You bind a DataTable to a BindingSource and then bind that to your control(s). You associate the BindingNavigator with the BindingSource and then its buttons, etc, are mapped to members of the BindingSource, e.g. the MoveFirst, MovePrevious, MoveNext and MoveLast methods. If you have multiple DataTables then you would have multiple BindingSources and BindingNavigators.
-
Mar 2nd, 2014, 09:56 AM
#3
Re: How to create multiple navigators in one form??
Just note that you won't be able to bind to the PictureBox so you should handle the CurrentChanged event of the appropriate BindingSource and then load the appropriate Image into the PictureBox. Just make sure you dispose the Images when appropriate. How you do that is up to you. You could dispose the old Image each time you display a new one or you could use a Dictionary or the like to store previously-used Images and then reuse them when appropriate.
-
Mar 2nd, 2014, 10:26 AM
#4
Thread Starter
Addicted Member
Re: How to create multiple navigators in one form??
I have no idea how to do that. Can you please tell me in steps or give me a website link which explains more of it???
because I tried using the binding tools and it didnt quite work.
Thank you!
-
Mar 2nd, 2014, 10:36 AM
#5
Re: How to create multiple navigators in one form??
You don't use the designer tools for binding if you're writing your own ADO.NET code. You have to have the data source, i.e. the DataSet, available at design time if you want to bind at design time. If you're creating the DataSet at run time then you bind at run time.
Add the BindingSource and the BindingNavigator to the form in the designer and set the BindingSource property of the BindingNavigator. In code, you bind the appropriate DataTable to the BindingSource by setting the DataSource property and then bind the BindingSource to your controls, e.g.
Code:
myBindingSource.DataSource = myDataTable
myTextBox.DataBindings.Add("Text", myBindingSource, "MyColumn")
-
Mar 2nd, 2014, 10:53 AM
#6
Thread Starter
Addicted Member
Re: How to create multiple navigators in one form??
Originally Posted by jmcilhinney
You don't use the designer tools for binding if you're writing your own ADO.NET code. You have to have the data source, i.e. the DataSet, available at design time if you want to bind at design time. If you're creating the DataSet at run time then you bind at run time.
Add the BindingSource and the BindingNavigator to the form in the designer and set the BindingSource property of the BindingNavigator. In code, you bind the appropriate DataTable to the BindingSource by setting the DataSource property and then bind the BindingSource to your controls, e.g.
Code:
myBindingSource.DataSource = myDataTable
myTextBox.DataBindings.Add("Text", myBindingSource, "MyColumn")
yeah I did that but it won't work properly. I'll send a picture of the error.
-
Mar 2nd, 2014, 11:06 AM
#7
Re: How to create multiple navigators in one form??
We don't need a picture of the error. What we need is for you to post the code, indicate the line on which the exception is thrown and provide the error message.
-
Mar 3rd, 2014, 05:11 AM
#8
Thread Starter
Addicted Member
Re: How to create multiple navigators in one form??
I got the error fixed and also found a way to navigate the picturebox.
Thank YoU!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|