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.

304 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

FIGURE 10-10 A Simple FlexGrid Control<br />

The width, measured in twips (there are about 1440 twips to an inch), of each column<br />

can be specified only at run time with the ColWidth property. A typical statement is<br />

msgFlex.ColWidth(3) = 1200, which sets the width of column 3 to 1200 twips. (The default<br />

column width is 555 twips.) Similarly, the RowHeight property specifies the height of each<br />

row. The width <strong>and</strong> height of the entire grid can be specified at design time by dragging the<br />

mouse or by setting the Width <strong>and</strong> Height properties.<br />

The grayed row <strong>and</strong> column in Figure 10-10 are referred to as fixed. Fixed rows <strong>and</strong><br />

columns must be at the top <strong>and</strong> left sides of the grid. The number of fixed rows <strong>and</strong> columns<br />

is specified by the FixedRows <strong>and</strong> FixedCols properties. The grid in Figure 10-10 has the<br />

default settings FixedRows = 1 <strong>and</strong> FixedCols = 1.<br />

If the width of the grid is too small to show all the columns, a horizontal scroll bar will<br />

automatically appear across the bottom of the grid. Then, during run time, the nonfixed<br />

columns can be scrolled to reveal the hidden columns. Similarly, a vertical scroll bar appears<br />

when the height of the grid is too small to show all the rows. Scroll bars can be suppressed<br />

by setting the ScrollBars property of the grid to 0 – flexScrollBarNone. (The default value<br />

of the ScrollBars property is 3 – flexScrollBarBoth.)<br />

The individual small rectangles are called cells. Each cell is identified by its row <strong>and</strong><br />

column numbers. At any time, one cell is singled out as the current cell. Initially, the cell in<br />

row 1, column 1 is the current cell. The pair of statements msgFlex.Row = m, msgFlex.Col<br />

= n set the current cell to the cell in the mth row <strong>and</strong> nth column. When the user clicks on a<br />

nonfixed cell, it becomes the current cell. The cell’s border becomes dotted, its row number<br />

is assigned to the Row property, <strong>and</strong> its column number is assigned to the Col property. (In<br />

Figure 10-10 the cell in row 2, column 4 is the current cell.) The horizontal <strong>and</strong> vertical lines<br />

forming the cells can be turned off by setting the GridLines property to 0 – flexGridNone.<br />

Unfortunately, you can’t just place text into a cell by clicking on the cell <strong>and</strong> typing, as<br />

you would with a text box. The statement msgFlex.Text = str places the value of str into the<br />

current cell <strong>and</strong> the statement str = msgFlex.Text reads the contents of the current cell. The<br />

text inside all the nonfixed cells of column n can be displayed left-aligned, right-aligned, or<br />

centered with a statement of the form msgFlex.ColAlignment(n) = r, where r is 1 for leftalignment,<br />

7 for right-alignment, <strong>and</strong> 4 for centered. The fixed cells of column n can be justified<br />

with a statement of the form msgFlex.FixedAlignment(n) = r.<br />

EXAMPLE 1<br />

The following program uses a grid to display an improved version of the table of student expenses from<br />

Example 5 of Section 2.5. The five expense categories <strong>and</strong> numeric data for the table are stored in the<br />

sequential file STCOSTS.TXT. Each record of the file consists of a string followed by four numbers.<br />

Object Property Setting<br />

frmCosts Caption Average Expenses of Commuter Students (1995–96)<br />

msgCosts BorderStyle 0 – flexBorderNone<br />

Cols 5<br />

FixedCols 0<br />

FixedRows 0<br />

Font Courier New<br />

GridLines 0 – flexGridNone

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

Saved successfully!

Ooh no, something went wrong!