Export (0) Print
Expand All

TemplateGroupCollection Class

Note: This class is new in the .NET Framework version 2.0.

Represents a collection of TemplateGroup objects within a control designer. This class cannot be inherited.

Namespace: System.Web.UI.Design
Assembly: System.Design (in system.design.dll)

public sealed class TemplateGroupCollection : IList, ICollection, IEnumerable
public final class TemplateGroupCollection implements IList, ICollection, 
	IEnumerable
public final class TemplateGroupCollection implements IList, ICollection, 
	IEnumerable

The ControlDesigner class, and any derived class, defines the TemplateGroups property as a TemplateGroupCollection object. The TemplateGroupCollection property is typically used only by a design host such as Visual Studio 2005.

The collection dynamically increases in size as objects are added. Indexes in this collection are zero-based. Use the Count property to determine how many groups are in the collection.

Additionally, use the TemplateGroupCollection methods and properties to provide the following functionality:

  • The Add method to add a single group to the collection.

  • The Insert method to add a group at a particular index within the collection.

  • The Remove method to remove a group.

  • The RemoveAt method to remove the group at a particular index.

  • The Contains method to determine whether a particular group is already in the collection.

  • The IndexOf method to retrieve the index of a group within the collection.

  • The Item indexer to get or set the group at a particular index, using array notation.

  • The AddRange method to add multiple groups to the collection.

    You can add multiple groups either as an array of groups or as a TemplateGroupCollection object that you retrieve through the TemplateGroups property of another control designer.

  • The Clear method to remove all groups from the collection.

The following code example demonstrates how to define a simple control designer that is derived from the ControlDesigner class. The derived control designer implements the TemplateGroups property by getting the template groups that are defined for the base class and adding a template group that is specific to the derived control designer.

using System;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using System.Web.UI.Design.WebControls;
using System.ComponentModel;
using System.ComponentModel.Design;

namespace Examples.AspNet
{
    // Define a simple control designer that adds a
    // template group to the template group collection.
    class DerivedControlDesigner : System.Web.UI.Design.ControlDesigner
    {
        private DerivedControl internalControl = null;

        private const String templateGroupName = "My template group";
        private const String templateDefinitionName1 = "First";
        private const String templateDefinitionName2 = "Second";
        private TemplateGroup internalGroup = null;

        // Override the read-only TemplateGroups property.
        // Get the base group collection, and add a group 
        // with two template definitions for the derived
        // control designer.
        public override TemplateGroupCollection TemplateGroups
        {
            get
            {
                // Start with the groups defined by the base designer class.
                TemplateGroupCollection groups = base.TemplateGroups;

                if (internalGroup == null) 
                {
                    // Define a new group with two template definitions.
                    internalGroup = new TemplateGroup(templateGroupName, 
                                                internalControl.ControlStyle);

                    TemplateDefinition templateDef1 = new TemplateDefinition(this, 
                        templateDefinitionName1, internalControl, 
                        templateDefinitionName1, internalControl.ControlStyle);

                    TemplateDefinition templateDef2 = new TemplateDefinition(this, 
                        templateDefinitionName2, internalControl, 
                        templateDefinitionName2, internalControl.ControlStyle);

                    internalGroup.AddTemplateDefinition(templateDef1);
                    internalGroup.AddTemplateDefinition(templateDef2);
                }


                // Add the new template group to the collection.
                groups.Add(internalGroup);

                return groups;
            }
        }

    }

    // Define a simple web control, and associate it with the designer.
    [DesignerAttribute(typeof(DerivedControlDesigner),
                       typeof(IDesigner))]
    public class DerivedControl : WebControl
    {
        // Define derived control behavior here.
    }

}

System.Object
  System.Web.UI.Design.TemplateGroupCollection

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0
Show:
© 2014 Microsoft