EditorPartCollection Constructors

Definition

Initializes a new instance of the EditorPartCollection class.

Overloads

EditorPartCollection()

Initializes an empty new instance of the EditorPartCollection class.

EditorPartCollection(ICollection)

Initializes a new instance of the EditorPartCollection class by passing in an ICollection collection of EditorPart controls.

EditorPartCollection(EditorPartCollection, ICollection)

Initializes a new instance of the EditorPartCollection class by passing in an EditorPartCollection collection of EditorPart controls, and an ICollection collection of additional EditorPart controls.

EditorPartCollection()

Initializes an empty new instance of the EditorPartCollection class.

public:
 EditorPartCollection();
public EditorPartCollection ();
Public Sub New ()

Remarks

The EditorPartCollection constructor initializes an empty instance of the EditorPartCollection class. This overload of the constructor is used internally by the EditorZone class in its CreateEditorParts method to create an empty collection object. The zone then creates instances of all the EditorPart controls declared in the child zone template, and uses an internal method to add them to the collection.

You cannot use this overload of the EditorPartCollection constructor to create a new instance of EditorPartCollection and add EditorPart controls to it. You must use one of the other overloads for the EditorPartCollection constructor instead.

See also

Applies to

EditorPartCollection(ICollection)

Initializes a new instance of the EditorPartCollection class by passing in an ICollection collection of EditorPart controls.

public:
 EditorPartCollection(System::Collections::ICollection ^ editorParts);
public EditorPartCollection (System.Collections.ICollection editorParts);
new System.Web.UI.WebControls.WebParts.EditorPartCollection : System.Collections.ICollection -> System.Web.UI.WebControls.WebParts.EditorPartCollection
Public Sub New (editorParts As ICollection)

Parameters

editorParts
ICollection

An ICollection of EditorPart controls.

Examples

The following code example demonstrates how to create a custom EditorPartCollection and, even though the collection is read-only, still perform a batch operation to change the individual EditorPart controls in the collection. For the full code required to run the example, see the Example section of the EditorPartCollection class overview.

The code in the Button1_Click event creates an ArrayList object, adds two of the three EditorPart controls in the page to the object, and then creates a new EditorPartCollection object using the EditorPartCollection constructor. It also demonstrates how you can make changes to the underlying EditorPart controls, even though the collection is read-only.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  protected void Button1_Click(object sender, EventArgs e)
  {
    ArrayList list = new ArrayList(2);
    list.Add(AppearanceEditorPart1);
    list.Add(PropertyGridEditorPart1);
    // Pass an ICollection object to the constructor.
    EditorPartCollection myParts = new EditorPartCollection(list);
    foreach (EditorPart editor in myParts)
    {
      editor.BackColor = System.Drawing.Color.LightBlue;
      editor.Description = "My " + editor.DisplayTitle + " editor.";
    }

    // Use the IndexOf property to locate an EditorPart control.
    int propertyGridPart = myParts.IndexOf(PropertyGridEditorPart1);
    myParts[propertyGridPart].ChromeType = PartChromeType.TitleOnly;

    // Use the Contains method to see if an EditorPart exists.
    if(!myParts.Contains(LayoutEditorPart1))
      LayoutEditorPart1.BackColor = System.Drawing.Color.LightYellow;
    
    // Use the CopyTo method to create an array of EditorParts.
    EditorPart[] partArray = new EditorPart[3];
    partArray[0] = LayoutEditorPart1;
    myParts.CopyTo(partArray,1);
    Label1.Text = "<h3>EditorParts in Custom Array</h3>";
    foreach (EditorPart ePart in partArray)
    {
      Label1.Text += ePart.Title + "<br />";
    }

  }

</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

  Protected Sub Button1_Click(ByVal sender As Object, _
    ByVal e As EventArgs)
    
    Dim list As New ArrayList(2)
    list.Add(AppearanceEditorPart1)
    list.Add(PropertyGridEditorPart1)
    ' Pass an ICollection object to the constructor.
    Dim myParts As New EditorPartCollection(list)
    Dim editor As EditorPart
    For Each editor In myParts
      editor.BackColor = System.Drawing.Color.LightBlue
      editor.Description = "My " + editor.DisplayTitle + " editor."
    Next editor
    
    ' Use the IndexOf property to locate an EditorPart control.
    Dim propertyGridPart As Integer = _
      myParts.IndexOf(PropertyGridEditorPart1)
    myParts(propertyGridPart).ChromeType = PartChromeType.TitleOnly
    
    ' Use the Contains method to see if an EditorPart exists.
    If Not myParts.Contains(LayoutEditorPart1) Then
      LayoutEditorPart1.BackColor = System.Drawing.Color.LightYellow
    End If
    
    ' Use the CopyTo method to create an array of EditorParts.
    Dim partArray(2) As EditorPart
    partArray(0) = LayoutEditorPart1
    myParts.CopyTo(partArray, 1)
    Label1.Text = "<h3>EditorParts in Custom Array</h3>"
    Dim ePart As EditorPart
    For Each ePart In partArray
      Label1.Text += ePart.Title + "<br />"
    Next ePart

  End Sub

</script>

You can load the page in a browser and switch the page into edit mode by selecting Edit in the Display Mode drop-down list control. You can click the verbs menu (the downward arrow) in the title bar of the TextDisplayWebPart control, and click Edit to edit the control. When the editing user interface (UI) is visible, you can see all the EditorPart controls. You click the Create EditorPartCollection button to see the effects on the two EditorPart controls that are added to the EditorPartCollection object.

Remarks

The EditorPartCollection constructor initializes an instance of the EditorPartCollection class and passes in a collection of EditorPart controls. This is one overload of the EditorPartCollection constructor that you can use to create a new EditorPartCollection object and add EditorPart controls to it.

Even though the EditorPartCollection instance created by the constructor is read-only, you can still access the individual EditorPart controls in the collection programmatically and call their properties and methods.

One common scenario for using the EditorPartCollection constructor would be if you want to perform some batch operation on an entire set of EditorPart controls, such as changing the content, appearance, or position of a related group of them.

Another common scenario for using the EditorPartCollection constructor is developing custom EditorPart controls that you want to associate with a server control, so that users can edit custom properties on your control. In this scenario, your server control must implement the IWebEditable interface, and as part of that task, it must implement the CreateEditorParts method. In that method, to enable the custom EditorPart controls to edit your server control, you must add the EditorPart controls to an ICollection instance, such as an ArrayList object. Then you can pass the collection of EditorPart controls to the EditorPartCollection constructor to create a new EditorPartCollection object, which the EditorZoneBase zone uses to set up all the controls and begin the editing process.

See also

Applies to

EditorPartCollection(EditorPartCollection, ICollection)

Initializes a new instance of the EditorPartCollection class by passing in an EditorPartCollection collection of EditorPart controls, and an ICollection collection of additional EditorPart controls.

public:
 EditorPartCollection(System::Web::UI::WebControls::WebParts::EditorPartCollection ^ existingEditorParts, System::Collections::ICollection ^ editorParts);
public EditorPartCollection (System.Web.UI.WebControls.WebParts.EditorPartCollection existingEditorParts, System.Collections.ICollection editorParts);
new System.Web.UI.WebControls.WebParts.EditorPartCollection : System.Web.UI.WebControls.WebParts.EditorPartCollection * System.Collections.ICollection -> System.Web.UI.WebControls.WebParts.EditorPartCollection
Public Sub New (existingEditorParts As EditorPartCollection, editorParts As ICollection)

Parameters

existingEditorParts
EditorPartCollection

An ICollection of existing EditorPart controls in a zone.

editorParts
ICollection

An ICollection of EditorPart controls not in a zone, but created programmatically.

See also

Applies to