EventDescriptorCollection::Item Property (Int32)

 

Gets or sets the event with the specified index number.

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

public:
property EventDescriptor^ default[
	int index
] {
	virtual EventDescriptor^ get(int index);
}

Parameters

index
Type: System::Int32

The zero-based index number of the EventDescriptor to get or set.

Property Value

Type: System.ComponentModel::EventDescriptor^

The EventDescriptor with the specified index number.

Exception Condition
IndexOutOfRangeException

index is not a valid index for Item.

The index number is zero-based. Therefore, you must subtract 1 from the numerical position of a particular EventDescriptor to access that EventDescriptor. For example, to get the third EventDescriptor, you need to specify myColl[2].

The following code example uses the Item property to print the name of the EventDescriptor specified by the index number in a text box. Because the index number is zero-based, this example prints the name of the second EventDescriptor. It requires that button1 and textBox1 have been instantiated on a form.

private:
   void PrintIndexItem()
   {

      // Creates a new collection and assigns it the events for button1.
      EventDescriptorCollection^ events = TypeDescriptor::GetEvents( button1 );

      // Prints the second event's name.
      textBox1->Text = events[ 1 ]->ToString();
   }

.NET Framework
Available since 1.1
Return to top
Show: