Adding Visual FoxPro Containers

In addition to form sets and forms, Visual FoxPro provides four base container classes.

Visual FoxPro Container Classes  
Command button group Option button group
Grid Page frame

To add container objects to a form

  • In the Form Controls toolbar, select the desired container object (button group, grid, option button group, or page frame) button and drag it to size in the form.

When you add a command button group or an option button group to a form in the Form Designer, the group contains two buttons by default. When you add a page frame to a form, the page frame contains two pages by default. You can add more buttons or pages by setting the ButtonCount property or the PageCount property to the number you want.

When you add a grid to a form, the ColumnCount property is set to – 1 by default, which indicates AutoFill. At run time, the grid will display as many columns as there are fields in the RowSource table. If you don't want AutoFill, you can specify the number of columns by setting the grid's ColumnCount property.

For more information about these container objects, see Using Controls.

Collection and Count Properties

All container objects in Visual FoxPro have a count property and a collection property associated with them. The collection property is an array referencing each contained object. The count property is a numeric property indicating the number of contained objects.

The collection and count properties for each container are named according to the type of object that can be contained in the container. The following table lists the containers and the corresponding collection and count properties.

Container Collection Property Count Property
Application Objects
Forms
Count
FormCount
FormSet Forms FormCount
Form Objects
Controls
Count
ControlCount
PageFrame Pages PageCount
Page Controls ControlCount
Grid Columns ColumnCount
CommandGroup Buttons ButtonCount
OptionGroup Buttons ButtonCount
Column Controls ControlCount
ToolBar Controls ControlCount
Container Controls ControlCount
Control Controls ControlCount

These properties allow you to use a loop to programmatically manipulate all or specific contained objects. For example, the following lines of code set the BackColor property of columns in a grid to alternating green and red:

o = THISFORM.grd1
FOR i = 1 to o.ColumnCount
   IF i % 2 = 0 && Even-numbered column
      o.Columns(i).BackColor = RGB(0,255,0) && Green
   ELSE
      o.Columns(i).BackColor = RGB(255,0,0) && Red
   ENDIF
ENDFOR

See Also

Addition of Objects to Forms | Adding Visual FoxPro Controls to a Form | Creating Forms | Adding User-Defined Objects to a Form | Extending Forms with Form Sets | Adding Controls to a Form with the Component Gallery | Adding Controls to a Wizard-Generated Form | Adding User-Defined Objects to a Form | Selecting, Moving, and Resizing Form Controls | Aligning Controls in Forms | Setting Tab Order for Controls