Bearbeiten

Freigeben über


HtmlElementCollection.Item[] Property

Definition

Gets an item from the collection.

Overloads

Item[Int32]

Gets an item from the collection by specifying its numerical index.

Item[String]

Gets an item from the collection by specifying its name.

Remarks

HtmlElementCollection objects are read-only. To add an element to an HTML document, use methods such as InsertAdjacentElement and AppendChild.

Item[Int32]

Gets an item from the collection by specifying its numerical index.

public:
 property System::Windows::Forms::HtmlElement ^ default[int] { System::Windows::Forms::HtmlElement ^ get(int index); };
public System.Windows.Forms.HtmlElement this[int index] { get; }
public System.Windows.Forms.HtmlElement? this[int index] { get; }
member this.Item(int) : System.Windows.Forms.HtmlElement
Default Public ReadOnly Property Item(index As Integer) As HtmlElement

Parameters

index
Int32

The position from which to retrieve an item from the collection.

Property Value

An item from the collection by specifying its numerical index.

Remarks

Elements in an HtmlElementCollection are not guaranteed to be in source code order. In other words, just because a DIV element is the first element inside of a BODY tag does not mean that the first element of the collection will be the DIV element.

Applies to

Item[String]

Gets an item from the collection by specifying its name.

public:
 property System::Windows::Forms::HtmlElement ^ default[System::String ^] { System::Windows::Forms::HtmlElement ^ get(System::String ^ elementId); };
public System.Windows.Forms.HtmlElement this[string elementId] { get; }
public System.Windows.Forms.HtmlElement? this[string elementId] { get; }
member this.Item(string) : System.Windows.Forms.HtmlElement
Default Public ReadOnly Property Item(elementId As String) As HtmlElement

Parameters

elementId
String

The Name or Id attribute of the element.

Property Value

An HtmlElement, if the named element is found. Otherwise, null.

Examples

The following code example finds a FORM object using its name, and submits its data to the server programmatically. The code example requires that your application hosts a WebBrowser control named webBrowser1.

private void SubmitForm(String formName)
{
    HtmlElementCollection elems = null;
    HtmlElement elem = null;

    if (webBrowser1.Document != null)
    {
        HtmlDocument doc = webBrowser1.Document;
        elems = doc.All.GetElementsByName(formName);
        if (elems != null && elems.Count > 0)
        {
            elem = elems[0];
            if (elem.TagName.Equals("FORM"))
            {
                elem.InvokeMember("Submit");
            }
        }
    }
}
Private Sub SubmitForm(ByVal FormName As String)
    Dim Elems As HtmlElementCollection
    Dim Elem As HtmlElement

    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            Elems = .All.GetElementsByName(FormName)
            If (Not Elems Is Nothing And Elems.Count > 0) Then
                Elem = Elems(0)
                If (Elem.TagName.Equals("FORM")) Then
                    Elem.InvokeMember("Submit")
                End If
            End If
        End With
    End If
End Sub

Applies to