19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

place an x in the check box next to “Microsoft Data Bound List Controls 6.0” for the other<br />

two controls.)<br />

■ USING THE FLEXGRID CONTROL<br />

When you attach the FlexGrid control to a table via a data control, the FlexGrid control will<br />

display the entire contents of the table, including the field names. If the table is too large to<br />

be displayed in entirety, scroll bars will automatically appear to allow you to scroll to other parts<br />

of the table. The FlexGrid control is discussed in Section 10.3. The gray fixed row at the top<br />

will show the field names. You should set the FixedCols property to 0 to avoid having a blank<br />

fixed column at the left. If some of the fields have long entries, you should widen the corresponding<br />

columns with the ColWidth method in Form_Load. Although you can use code to<br />

alter the contents of the cells in a FlexGrid (as shown in Section 10.3), changes in the cells of<br />

the FlexGrid will not alter the contents of the database.<br />

You can use an SQL statement to specify the fields displayed in a FlexGrid control. For<br />

instance, if the control has datCities as its DataSource <strong>and</strong> the DatabaseName setting for<br />

datCities is MEGACTY2.MDB, then the statement<br />

datCities.RecordSource = “SELECT city, country FROM Cities”<br />

causes the FlexGrid to display only the first two columns of the Cities table. The same effect<br />

can be achieved at design time by setting the RecordSource property of datCities to<br />

SELECT city, country FROM Cities<br />

EXAMPLE 1<br />

Creating <strong>and</strong> Designing Databases 339<br />

The following program displays the contents of the Cities table of the MEGACTY2.MDB database. When<br />

you click on the comm<strong>and</strong> button, the FlexGrid displays the cities, their countries, <strong>and</strong> currency. Also, the<br />

caption of the comm<strong>and</strong> button changes to “Show City, Country, Populations”. The next time you click<br />

the comm<strong>and</strong> button, the contents of the FlexGrid returns to its original state.<br />

Object Property Setting<br />

frm12_3_1 Caption Megacities<br />

datCities Caption Large World Cities<br />

Database MEGACTY2.MDB<br />

Name<br />

Record Cities<br />

Source<br />

msgCities Data datCities<br />

Source<br />

FixedCols 0<br />

cmdShow Caption Show City,<br />

Country,<br />

Currency<br />

Private Sub cmdShow_Click()<br />

If cmdShow.Caption = “Show City, Country, Currency” Then ‘<br />

Join the two tables <strong>and</strong> display cities, countries, <strong>and</strong> currency<br />

datCities.RecordSource = “SELECT city, Cities.country, currency FROM “ & _<br />

“Cities INNER JOIN Countries ON Countries.country = Cities.country “ & _<br />

“ORDER BY city”<br />

datCities.Refresh<br />

cmdShow.Caption = “Show City, Country, Populations”<br />

Else<br />

datCities.RecordSource = “Cities”<br />

datCities.Refresh<br />

cmdShow.Caption = “Show City, Country, Currency”

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!