EditorPartCollection.CopyTo Method (EditorPart(), Int32)


Copies the collection to an array of EditorPart controls.

Namespace:   System.Web.UI.WebControls.WebParts
Assembly:  System.Web (in System.Web.dll)

Public Sub CopyTo (
	array As EditorPart(),
	index As Integer


Type: System.Web.UI.WebControls.WebParts.EditorPart()

An EditorPart to contain the copied collection of controls.

Type: System.Int32

The starting point in the array at which to place the collection contents.

The CopyTo method is useful when you want to create a custom array that can contain the EditorPart controls in the EditorPartCollection object, a subset of those controls, or a superset of those controls.

The following code example demonstrates how to use the CopyTo method to create a custom array of EditorPart controls. 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 array of EditorPart controls, adds the LayoutEditorPart1 control to the array, and then uses the CopyTo method to copy the controls from the EditorPartCollection object to the array.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

  Protected Sub Button1_Click(ByVal sender As Object, _
    ByVal e As EventArgs)

    Dim list As New ArrayList(2)
    ' 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(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


When you load the page in a browser, you can 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. If you click the Create EditorPartCollection button, you will notice that the titles of all the controls in the custom array are listed near the bottom of the page.

.NET Framework
Available since 2.0
Return to top