13. Creating Dynamic Frames : How You Can Create and Modify Fields Dynamically : How You Can Create Dynamic Composite Fields
 
Share this page                  
How You Can Create Dynamic Composite Fields
Composite fields are created dynamically using the same steps used to create a simple field. For a discussion of these steps, see How You Can Create Dynamic Simple Fields (see How You Can Create Dynamic Simple Fields).
However, creating a MatrixField object dynamically requires an additional step. When first instantiated, matrix fields contain no columns and no rows. Because you cannot insert a field into a matrix field cell that does not exist, you must specify the number of rows and columns before you insert any child fields.
Begin dynamic matrix field creation by specifying a number of rows and columns large enough to contain all the fields to be inserted. After all child fields have been added, remove the empty cells by setting the CollapsePolicy attribute.
The following code creates a matrix field, sets the number of rows and columns, populates the matrix field, and removes empty cells:
mfield = MatrixField.Create();
mfield.Rows = 25;
mfield.Columns = 4;