Button Control in VB Database

- In the last part of this tutorial, we have created a database application shown in the below figure:
- In today's lecture we will add few new features in the above application and at the end of today's lecture, the above application will looks like this.
- You can see in the below figure that now we have Button Control in VB Database.
Step 1 : Add, Save & Remove Buttons
- First of all open the application which we created in the previous part of this tutorial.
- Now add three buttons on it as shown in the below figure :
- Now click the button 1 and change its name from properties to Add, button 2 to Save and button 3 to Remove as shown in figure below.
- We have added buttons and also changed their names according to our requirement, now we are gonna add functionality in these buttons i.e. what function they perform when someone click them.
- Double click Add button and put this code in its function.
Try Me.Contact_FormBindingSource.AddNew() Catch ex As Exception End Try
- Now double click Save button and add this code in its function.
Try Me.ValidateChildren() Me.Contact_FormBindingSource.EndEdit() Me.TableAdapterManager.UpdateAll(Me.ContactsDataSet) Catch ex As Exception End Try
- Now double click the Remove button and add the following code in its function.
Try Me.Contact_FormBindingSource.RemoveCurrent() Catch ex As Exception End Try
- Now run your application and if everything's fine then when you click Add button, a new line will appear in the database where you can enter the next contact. After adding the contact, when you click on the Save button software will automatically save the contact in database and if you click the Remove button then the selected entry in database will be deleted.
Step 2 : Next & Previous Buttons
- Now add two more buttons from toolbar, just under these three buttons as shown in the figure below:
- Change their names to Previous and Next as shown in image below:
- Now double click the Previous button and add the below code in it.
Contact_FormBindingSource.MovePrevious()
- After that double click the Next button and add the below code in its function.
Contact_FormBindingSource.MoveNext()
- Now run your application and when you click the Next button the selection in database will move downward i.e towards the next entry and when you press previous it will move upward i.e towards the previous entry.
Step 3 : Move To Top & Move To End Buttons
- Now again add two more buttons as shown in the figure below:
- Remove Button1 to Move To End and Button2 to Move To Top as shown in below figure:
- Now double click on Move To End Button and insert the below code in it.
Contact_FormBindingSource.MoveLast()
- After that double click on Move To Top button and add the below code in its function.
Contact_FormBindingSource.MoveFirst()
- Now run your application, and check the working of these two buttons. When you click Move To Top button the database will rolled up and you will reached the first line and vice versa for second button.
- This software along with code has already been emailed to all the subscribed members. If someone didn't received it then post your email in the comments and i will send it to you.
- if someone wants this software along with the code then subscribe to our email newsletter and it will be automatically emailed to you.
×
![]()









































































