ID Number: Q84113
1.00
WINDOWS
Summary:
The example program below demonstrates how you can display labels in
the top row and left column of the Grid custom control at run time. It
is not possible to assign labels in a grid at design time.
This information applies to the Grid custom control provided with
Microsoft Professional Toolkit for Microsoft Visual Basic programming
system version 1.0 for Windows.
More Information:
The example program below assigns labels to a grid from the Form_Load
event procedure. It puts numbers down the left, labeling the first
non-fixed row as "1". It puts letters across the top, labeling the
first 26 non-fixed columns as "A" through "Z" then subsequent columns
with "AA", "AB", and so on.
Steps to Create Example Program
-------------------------------
1. Run Visual Basic, or from the File menu, choose New Project (ALT,
F, N) if Visual Basic is already running. Form1 is created by
default.
2. From the File menu, choose Add File. In the Files box, select the
GRID.VBX. The Grid tool appears in the Toolbox.
3. Select the Grid tool from the Toolbox, and place a grid (Grid1)
on Form1.
4. On the Properties bar, set the Grid Cols and Rows properties to 30.
5. Double-click the form to open the Code window. In the Procedure
box, select Load. Enter the following code:
Sub Form_Load ()
Dim i As Integer
' Make sure grid has at least one fixed column and row
If Grid1.FixedCols < 1 Or Grid1.FixedRows < 1 Then
Stop
End If
' Put letters across top
For i = 0 To Grid1.Cols - 2
Grid1.Col = i + 1
Grid1.Row = 0
Grid1.Text = Chr$(i Mod 26 + Asc("A"))
' If more than 26 columns, use double letter labels
If i + Asc("A") > Asc("Z") Then
Grid1.Text = Chr$(i \ 26 - 1 + Asc("A")) + Grid1.text
End If
Grid1.FixedAlignment(Grid1.Col) = 2 ' centered
Next
' Put numbers down left edge
For i = 1 To Grid1.Rows - 1
Grid1.Col = 0
Grid1.Row = i
Grid1.Text = Format$(i)
Next
Grid1.FixedAlignment(0) = 2 ' centered
End Sub
6. Press F5 to run the program.
Additional reference words: 1.00