Understanding Container and Control Objects

You can add the following types of objects to a form:

Objects in Visual FoxPro belong in one of two categories, depending on the nature of the class they are based on:

  • Containers can hold other containers or controls. They can act as the parent object for other objects. For example, a form, as a container, is the parent object of a check box on that form.

  • Controls can be placed in containers, but cannot be the parent for other objects. For example, a check box cannot contain any other object.

The Form Designer allows you to design both containers and controls.

Container Can contain


Headers, and any objects except form sets, forms, toolbars, timers, and other columns

Command button group

Command buttons

Form set

Forms, toolbars


Page frames, grids, any controls



Option button group

Option buttons

Page frame



Grids, any 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.

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:

 CopyCode imageCopy Code
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
      o.Columns(i).BackColor = RGB(255,0,0) && Red

See Also

© , 1996-2020 • Updated: 11/10/20
Comment or report problem with topic