Microsoft KB Archive/84113

= How to Create Column and Row Labels in VB Grid Custom Control =

Article ID: 84113

Article Last Modified on 12/12/2003

-

APPLIES TO


 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Visual Basic 2.0 Professional Edition
 * Microsoft Visual Basic 3.0 Professional Edition
 * Microsoft Professional Toolkit for Microsoft Visual Basic programming system for Windows

-



This article was previously published under Q84113



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.



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 &quot;1&quot;. It puts letters across the top, labeling the first 26 non-fixed columns as &quot;A&quot; through &quot;Z&quot; then subsequent columns with &quot;AA&quot;, &quot;AB&quot;, and so on.

Steps to Create Example Program
 Run Visual Basic for Windows, or from the File menu, choose New Project (press ALT, F, N) if Visual Basic for Windows is already running. Form1 is created by default. From the File menu, choose Add File. In the Files box, select the GRID.VBX. The Grid tool appears in the Toolbox. Select the Grid tool from the Toolbox, and place a grid (Grid1) on Form1. On the Properties bar, set the Grid Cols and Rows properties to 30.  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(&quot;A&quot;)) ' If more than 26 columns, use double letter labels. If i + Asc(&quot;A&quot;) > Asc(&quot;Z&quot;) Then Grid1.Text = Chr$(i \ 26 - 1 + Asc(&quot;A&quot;)) + 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  Press the F5 key to run the program.</ol>

Additional query words: 1.00 2.00 3.00

Keywords: KB84113

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.