แก้ไข

แชร์ผ่าน


PropertyDescriptorCollection.Item[] Property

Definition

Gets or sets the specified PropertyDescriptor.

Overloads

Item[Int32]

Gets or sets the PropertyDescriptor at the specified index number.

Item[String]

Gets or sets the PropertyDescriptor with the specified name.

Item[Int32]

Source:
PropertyDescriptorCollection.cs
Source:
PropertyDescriptorCollection.cs
Source:
PropertyDescriptorCollection.cs

Gets or sets the PropertyDescriptor at the specified index number.

public:
 virtual property System::ComponentModel::PropertyDescriptor ^ default[int] { System::ComponentModel::PropertyDescriptor ^ get(int index); };
public virtual System.ComponentModel.PropertyDescriptor this[int index] { get; }
member this.Item(int) : System.ComponentModel.PropertyDescriptor
Default Public Overridable ReadOnly Property Item(index As Integer) As PropertyDescriptor

Parameters

index
Int32

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

Property Value

The PropertyDescriptor with the specified index number.

Exceptions

The index parameter is not a valid index for Item[Int32].

Examples

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

void PrintIndexItem()
{
   
   // Creates a new collection and assigns it the properties for button1.
   PropertyDescriptorCollection^ properties = TypeDescriptor::GetProperties( button1 );
   
   // Prints the second property's name.
   textBox1->Text = properties[ 1 ]->ToString();
}
private void PrintIndexItem() {
    // Creates a new collection and assigns it the properties for button1.
    PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1);
 
    // Prints the second property's name.
    textBox1.Text = properties[1].ToString();
 }
Private Sub PrintIndexItem()
    ' Creates a new collection and assigns it the properties for button1.
    Dim properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(button1)
       
    ' Prints the second property's name.
    textBox1.Text = properties(1).ToString()
End Sub

Remarks

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

See also

Applies to

Item[String]

Source:
PropertyDescriptorCollection.cs
Source:
PropertyDescriptorCollection.cs
Source:
PropertyDescriptorCollection.cs

Gets or sets the PropertyDescriptor with the specified name.

public:
 virtual property System::ComponentModel::PropertyDescriptor ^ default[System::String ^] { System::ComponentModel::PropertyDescriptor ^ get(System::String ^ name); };
public virtual System.ComponentModel.PropertyDescriptor this[string name] { get; }
public virtual System.ComponentModel.PropertyDescriptor? this[string name] { get; }
member this.Item(string) : System.ComponentModel.PropertyDescriptor
Default Public Overridable ReadOnly Property Item(name As String) As PropertyDescriptor

Parameters

name
String

The name of the PropertyDescriptor to get from the collection.

Property Value

The PropertyDescriptor with the specified name, or null if the property does not exist.

Examples

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

void PrintIndexItem2()
{
   
   // Creates a new collection and assigns it the properties for button1.
   PropertyDescriptorCollection^ properties = TypeDescriptor::GetProperties( button1 );
   
   // Sets a PropertyDescriptor to the specific property.
   PropertyDescriptor^ myProperty = properties[ "Opacity" ];
   
   // Prints the display name for the property.
   textBox1->Text = myProperty->DisplayName;
}
private void PrintIndexItem2() {
   // Creates a new collection and assigns it the properties for button1.
   PropertyDescriptorCollection properties =
       TypeDescriptor.GetProperties(button1);

   // Sets a PropertyDescriptor to the specific property.
   PropertyDescriptor myProperty = properties["Opacity"];

   // Prints the display name for the property.
   textBox1.Text = myProperty.DisplayName;
}
Private Sub PrintIndexItem2()
    ' Creates a new collection and assigns it the properties for button1.
    Dim properties As PropertyDescriptorCollection = _
       TypeDescriptor.GetProperties(button1)
       
    ' Sets a PropertyDescriptor to the specific property.
    Dim myProperty As PropertyDescriptor = properties("Opacity")
       
    ' Prints the display name for the property.
    textBox1.Text = myProperty.DisplayName
End Sub

Remarks

The Item[] property is case-sensitive when searching for names. That is, the names "Pname" and "pname" are considered to be two different properties.

See also

Applies to