The magazine of the Melbourne PC User Group

Seeing the Basics: 
Adding grid capability to your VB applications

Tony Stevenson

The DBGrid Control

Adding grid capability to your Visual Basic applications can easily be achieved by using the DBGrid Control. Not only can you then subsequently control its functionality, you can also customise its appearance.

One of the easiest ways to get started with the DBGrid control is to use VB's Data Form Wizard. This is an Add-In that comes supplied with VB itself. (Add-Ins are software applications used to conveniently extend VB's development environment.)

Let's get started.
  1. To access the Data Form Wizard, click on the "Add-Ins" option of the VB main design menu, and then select the "Add-In Manager ..." option.

    The Add-In Manager dialog now appears, and from its list of available Add-Ins on your system, select the "VB Data Form Wizard" check box, and click the "OK" button.
  2. Now click the "Add-Ins" option of the VB main design menu once again, and you'll see the last entry is now the "Data Form Wizard ..." option. Click this now.

    The "Data Form Wizard--Introduction" dialog now appears. Since this is only an introductory form, click "Next" to move on to the next screen. (If you don't want to see this form again, click the check box labelled "Skip this screen in the future" before clicking "Next".)
  3. The dialog which now appears is the "Data Form Wizard--Database Type". Here you select the preferred database format for the sample application we are creating. Leave it pointing to the default option, "Access", which is Microsoft's own relational database management system. Click "Next" to continue.
  4. When the "Data Form Wizard--Database" dialog displays, click the "Browse ..." button to find the directory containing the "Biblio.mdb" database (this comes supplied with VB and we'll use it as our preferred database in our sample application). Click "Next" to continue.
  5. From the "Data Form Wizard--Form" dialog, select the "Grid (Datasheet)" option to nominate it as our desired form layout. Click "Next".
  6. The next dialog to appear is the "Data Form Wizard--Record Source". Click the down arrow of the "Record Source" combo box to reveal the different tables available in the "Biblio.mdb" database. For our application, choose the "Authors" table. Then select the button with the ">" caption. This will instruct VB to make all the fields in the "Authors" table available to our sample application. Click "Next" to continue.
  7. The next dialog, "Data Form Wizard--Control Selection" allows you to nominate what controls are to appear on the form being generated. For this exercise, check the options "Add", "Update", and "Close". Then click "Next".
  8. The last dialog is "Data Form Wizard--Finalised!" where VB suggests a name of "frmAuthors" for the form it will automatically generate. Leave it set on this default name and click the "Finish" button.

    VB will now go to work and create the sample project. This will consist of two forms--a main form and the second one, "frmAuthors", which contains the DBGrid. Now there is only one task left before running the application.
  9. On the main form (named Form1), add a command button, and in its Click event, add the following one line of code:
    frmAuthors.Show.
  10. Now run the application, and when the main form appears, click its command button. Viola! There is a form containing a fully-functional grid control, and best of all, it required only a single line of code to make it operational.
New definitive VB book

Platinum Edition: Using Visual Basic 5 is a comprehensive text that is suitable reading for both novice and experienced Visual Basic programmers.

It has been conveniently divided into sections allowing you to read about those aspects of VB which are of most concern to you at the moment.

The different sections cover:
  • Visual Basic fundamentals
  • VB controls, with an emphasis on VB 5.0's new controls, as well as a discussion of control arrays and containers
  • The steps involved in out-putting and displaying information
  • A discussion of VB from a professional developer's perspective, including the topics of classes, user interface design (one whole chapter is devoted to creating applications using a Multiple Document Interface), and online help
  • ActiveX controls and documents
  • Database programming
  • Web programming
  • Distributed Client/Server environment programming.
T he final section deals with advanced topics. These include how to create your own Visual Basic Add-In; building a Wizard; the steps involved in reading and writing entries in the Windows Registry and INI files; and how to leverage additional functionality out of your VB programs by calling the external functions available within the Windows API (Application Programming Interface).

The book has two appendixes.

The first appendix is a list of VB resources. Here you'll find information about third party controls which can simplify your VB programming, plus pointers to online VB resources and other VB books.

The second appendix lists the resources available on the companion CD-ROM, which includes sample code and applications used throughout the book; demonstration applications; and an electronic version of the book (in HTML format) that can be read using any Web browser. (The electronic version of the text contains extra material with chapters on security, SQL, multimedia, graphics, and Visual SourceSafe.)

Other material on the CD-ROM includes an invaluable VB Knowledge Base and a Visual Basic FAQ (Frequently Asked Questions). These features are handy, as it's very convenient to be able to search for information electronically, as opposed to thumbing through page after page looking for specific help.

So regardless of what level of VB experience you have, there is enough information contained within this book, and its companion CD-ROM, to keep even the most ambitious programmer well informed.

Loren D. Eidahl: Platinum Edition: Using Visual Basic 5
ISBN 0 7897 1412 4
1462 pages plus companion CD-ROM
Published by Que
Distributed in Australia by Prentice Hall
RRP: $99.95

Reprinted from the June 1998 issue of PC Update, the magazine of Melbourne PC User Group, Australia

[About Melbourne PC User Group]