Lesson 26: Using Microsoft DataGrid Control 6.0
In the previous lesson, we use textboxes or labels to display
data by connecting them to a database via Microsoft ADO data Control 6.0. The
textbox is not the only control that can display data from a database, many
other controls in Visual Basic can display data. One of the them is the DataGrid control. DataGrid
control can be used to display the entire table of a recordset of a
database. It allows users to view and edit data.
DataGrid control is the not the default item in the Visual Basic control toolbox, you have to add it from the VB6 components. To add the DataGrid control, click on the project on the menu bar and select components to access the dialog box that displays all the available VB6 components, as shown in the diagram below. Select Microsoft DataGrid Control 6.0 by clicking the checkbox beside this item. Before you exit the dialog box, you also need to select the Microsoft ADO data control so that you are able to access the database. Last, click on the OK button to exit the dialog box. Now you should be able to see that the DataGrid control and the ADO data control are added to the toolbox. The next step is to drag the DataGrid control and the ADO data control into the form.
DataGrid control is the not the default item in the Visual Basic control toolbox, you have to add it from the VB6 components. To add the DataGrid control, click on the project on the menu bar and select components to access the dialog box that displays all the available VB6 components, as shown in the diagram below. Select Microsoft DataGrid Control 6.0 by clicking the checkbox beside this item. Before you exit the dialog box, you also need to select the Microsoft ADO data control so that you are able to access the database. Last, click on the OK button to exit the dialog box. Now you should be able to see that the DataGrid control and the ADO data control are added to the toolbox. The next step is to drag the DataGrid control and the ADO data control into the form.
Figure 26.1: The Components Dialog Box
Figure 26.2: The Design Interface
Before you proceed , you need to create a database file using Microsoft Access. Here we create a database file to store the information of books and we named the table book. Having created the table, enter a few records, as shown in Figure 26.3 below:
Figure 26.3
Next, you need to connect the database to the ADO data control. To do that, right click on the ADO data control and select the ADODC properties, the following dialog box will appear.Figure 26.4: Data Link Properties
Figure 26.5: Property Pages
Finally you need to display the data in the DataGrid control. To accomplish this, go to the properties window and set the DataSource property of the DataGrid to Adodc1. You can also permit the user to add and edit your records by setting the AllowUpdate property to True. If you set this property to false, the user cannot edit the records. Now run the program and the runtime interface is shown in Figure 26.5 below:
0 comments:
Post a Comment