A grid control is like a two-dimensional array of textboxes:
Columns
0 1 2 3 4
_____________________________
0 |_____|_____|_____|_____|_____|
Rows 1 |_____|_____|_____|_____|_____|
2 |_____|_____|_____|_____|_____|
3 |_____|_____|_____|_____|_____|
4 |_____|_____|_____|_____|_____|
5 |_____|_____|_____|_____|_____|
6 |_____|_____|_____|_____|_____|
7 |_____|_____|_____|_____|_____|
8 |_____|_____|_____|_____|_____|
9 |_____|_____|_____|_____|_____|
(There is one big difference here, however: although we can display text in each cell of a grid control, users cannot type directly into a grid control's cells as they can with a textbox.) As you can see, grid controls make a perfect foundation for spreadsheets. We'll deal with grid controls in more detail later; for now, we simply add a new grid control to our ActiveX Web page:
<HTML>
<HEAD>
<TITLE>OCX Control Page</TITLE>
</HEAD>
<BODY LANGUAGE = VBScript ONLOAD = "Page_Initialize">
<CENTER>
<H1>OCX Control Page</H1>
</CENTER>
.
.
.
<!- Grid>
<PRE>
--> Grid1: <OBJECT CLASSID="clsid:a8c3b720-0b5a-101b-b22e-00aa0037b2fc"
HEIGHT=100 WIDTH=150 ID=Grid1></OBJECT>
</PRE>
.
.
.
We set the number of rows in the new grid control using the Rows property, and the number of columns with the Cols property. To make the new grid 3 x 3, we add this code:
<SCRIPT LANGUAGE = VBScript>
Sub Page_Initialize
Cmd1.Caption = "Hello"
Frame1.Caption = "Frame"
Panel1.Caption = "Panel"
--> Grid1.Rows = 3
--> Grid1.Cols = 3
.
.
.
End Sub
</SCRIPT>
</BODY>
</HTML>
Next, let's say we want to enter the number 5 in row 1, column 1. To do that, we first set the Row and Col properties (not to be confused with the Rows and Cols properties) to 1 and then enter "5" into the grid's Text property:
<SCRIPT LANGUAGE = VBScript>
Sub Page_Initialize
Cmd1.Caption = "Hello"
Frame1.Caption = "Frame"
Panel1.Caption = "Panel"
Grid1.Rows = 3
Grid1.Cols = 3
--> Grid1.Row = 1
--> Grid1.Col = 1
--> Grid1.Text = "5"
.
.
.
End Sub
</SCRIPT>
</BODY>
</HTML>
This places 5 in the grid control, as shown in Figure 6.1. Our grid control is a success. We'll say more about grid controls soon. For now, let's continue our overview of ActiveX controls with the graph control.