Components. Add The Flex Grid Control

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

The Flex Grid Control

Page 1 of 5

Lesson 97: The Flex Grid Control


The most common multidimensional array, the two dimensional array table, is best presented to your users in row and column format. The grid control offers a convenient way for you to display table data to your users. The users can navigate the table's values using scrollbars. Therefore, the grid control does not have to be as large as the table, because the grid control automatically displays scrollbars. To add the flex grid control to your toolbox, select project and components. Add the flex grid control:

Once it is added, you will see the yellow flex grid control in your toolbox:

http://www.saskschools.ca/~ehs/HeiseIntra/VB/Lesson97.html

2/4/2010

The Flex Grid Control

Page 2 of 5

When you place the grid control on your form, you will have to resize it before the control takes on a tabular appearance. As you expand the size of the control, it does not look to much like a table. The problem is that the table's default number of rows and columns are two. To fix this problem, you must configure the rows and columns in the properties window:

The grid control supports fixed rows and columns. These refer to rows and columns in a grid control that do not scroll when the user clicks the scrollbars. The fixed rows and columns provides labels that describe the data. The fixed rows and columns are often called row and column headers.

http://www.saskschools.ca/~ehs/HeiseIntra/VB/Lesson97.html

2/4/2010

The Flex Grid Control

Page 3 of 5

When working with the grid control, much code is needed to provide the grid with functionality. Call statements are used to break the code required by the grid control into smaller, more manageable procedures. This is referred to as modular programming (which refers to the practice of placing code with a single purpose in a general subroutine procedure and then calling the code from a second procedure.) Here is the code for the form load procedure (this example is based on the computer disk example used in the last lesson)

Private Sub Form_Load() Call SizeCells Call CenterCells

grdGrid.Row = 0 grdGrid.Col = 1 grdGrid.Text = "Single Sided; Low Density " grdGrid.Col = 2 grdGrid.Text = "Double Sided; Low Density" grdGrid.Col = 3 grdGrid.Text = "Singled Sided; High Density" grdGrid.Col = 4 grdGrid.Text = "Double Sided; High Density" grdGrid.Row = 1 grdGrid.Col = 0 grdGrid.Text = "3 1/2 inch" grdGrid.Col = 1 grdGrid.Text = "$2.30" grdGrid.Col = 2 grdGrid.Text = "$2.75" grdGrid.Col = 3 grdGrid.Text = "$3.20" grdGrid.Col = 4 grdGrid.Text = "$3.50"

http://www.saskschools.ca/~ehs/HeiseIntra/VB/Lesson97.html

2/4/2010

The Flex Grid Control

Page 4 of 5

grdGrid.Row = 2 grdGrid.Col = 0 grdGrid.Text = "5 1/4 inch" grdGrid.Col = 1 grdGrid.Text = "$1.75" grdGrid.Col = 2 grdGrid.Text = "$2.10" grdGrid.Col = 3 grdGrid.Text = "$2.60" grdGrid.Col = 4 grdGrid.Text = "$2.95" End Sub

Notice how the form load procedure is used to populate the cells in the grid control. To control cell size and cell alignment, two smaller procedures are created and each procedure is called by the form load procedure.

Private Sub SizeCells() Dim intColumn As Integer grdGrid.ColWidth(0) = 1100 For intColumn = 1 To 4 grdGrid.ColWidth(intColumn) = 2200 Next intColumn End Sub Private Sub CenterCells() Dim intColumn As Integer For intColumn = 1 To 4 grdGrid.ColAlignment(intColumn) = flexAlignCenterCenter Next intColumn End Sub

Notice that the size and alignment procedures are only applied to columns 1 through 4. Column 0, which is a fixed column reserved

http://www.saskschools.ca/~ehs/HeiseIntra/VB/Lesson97.html

2/4/2010

The Flex Grid Control

Page 5 of 5

for labels, is not formatted using either of the above two procedures. Here is the final result:

http://www.saskschools.ca/~ehs/HeiseIntra/VB/Lesson97.html

2/4/2010

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy