Share via


EditorPartCollection.IndexOf(EditorPart) Méthode

Définition

Retourne la position d'un membre particulier de la collection.

public:
 int IndexOf(System::Web::UI::WebControls::WebParts::EditorPart ^ editorPart);
public int IndexOf (System.Web.UI.WebControls.WebParts.EditorPart editorPart);
member this.IndexOf : System.Web.UI.WebControls.WebParts.EditorPart -> int
Public Function IndexOf (editorPart As EditorPart) As Integer

Paramètres

editorPart
EditorPart

EditorPart qui est membre de la collection.

Retours

Entier qui correspond à l'index d'un contrôle EditorPart dans la collection.

Exemples

L’exemple de code suivant montre comment utiliser la IndexOf méthode pour localiser un EditorPart contrôle dans un EditorPartCollection objet. Pour obtenir le code complet requis pour exécuter l’exemple, consultez la section Exemple de la vue d’ensemble de la EditorPartCollection classe.

Le code dans l’événement Button1_Click crée un EditorPartCollection objet, puis utilise la IndexOf méthode pour localiser le PropertyGridEditorPart1 contrôle dans la collection et définir sa ChromeType propriété.

<!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>

Lorsque vous chargez la page dans un navigateur, vous pouvez basculer la page en mode édition en sélectionnant Modifier dans le contrôle de liste déroulante Mode d’affichage . Vous pouvez cliquer sur le menu verbes (flèche vers le bas) dans la barre de titre du TextDisplayWebPart contrôle, puis cliquer sur Modifier pour modifier le contrôle. Lorsque l’interface utilisateur de modification est visible, vous pouvez voir tous les EditorPart contrôles. Si vous cliquez sur le bouton Créer un éditeurPartCollection , vous remarquerez que le PropertyGridEditorPart1 contrôle, qui se trouve en bas de la page, a un titre, mais aucune bordure.

Remarques

La IndexOf méthode est utile si vous avez plusieurs EditorPart contrôles sur une page de composants WebPart et que vous devez localiser un contrôle particulier dans la collection.

S’applique à

Voir aussi