Item Property (String)
Collapse the table of content
Expand the table of content

EventDescriptorCollection.Item Property (String)

 

Gets or sets the event with the specified name.

Namespace:   System.ComponentModel
Assembly:  System (in System.dll)

public virtual EventDescriptor this[
	string name
] { get; }

Parameters

name
Type: System.String

The name of the EventDescriptor to get or set.

Property Value

Type: System.ComponentModel.EventDescriptor

The EventDescriptor with the specified name, or null if the event does not exist.

The Item property is case-sensitive when searching for names. That is, the names "Ename" and "ename" are considered to be two different events.

System_CAPS_noteNote

The HostProtectionAttribute attribute applied to this class has the following Resources property value: Synchronization. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

The following code example uses the Item property to print the type of the component for the EventDescriptor specified by the index. It requires that button1 and textBox1 have been instantiated on a form.

private void PrintIndexItem2() {
    // Creates a new collection and assigns it the events for button1.
    EventDescriptorCollection events = TypeDescriptor.GetEvents(button1);

    // Sets an EventDescriptor to the specific event.
    EventDescriptor myEvent = events["KeyDown"];

    // Prints the name of the event.
    textBox1.Text = myEvent.Name;
 }

.NET Framework
Available since 1.1
Return to top
Show:
© 2016 Microsoft