Export (0) Print
Expand All

PropertyDescriptorCollection Class

Represents a collection of PropertyDescriptor objects.

For a list of all members of this type, see PropertyDescriptorCollection Members.

System.Object
   System.ComponentModel.PropertyDescriptorCollection

[Visual Basic]
Public Class PropertyDescriptorCollection
   Implements IList, ICollection, IEnumerable, IDictionary
[C#]
public class PropertyDescriptorCollection : IList, ICollection,
   IEnumerable, IDictionary
[C++]
public __gc class PropertyDescriptorCollection : public IList,
   ICollection, IEnumerable, IDictionary
[JScript]
public class PropertyDescriptorCollection implements IList,
   ICollection, IEnumerable, IDictionary

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

PropertyDescriptorCollection is read-only; it does not implement methods that add or remove properties. You must inherit from this class to implement these methods.

Using the properties available in the PropertyDescriptorCollection class, you can query the collection about its contents. Use the Count property to determine the number of elements in the collection. Use the Item property to get a specific property by index number or by name.

In addition to properties, you can use the Find method to get a description of the property with the specified name from the collection.

Example

[Visual Basic, C#, C++] The following example creates a new PropertyDescriptorCollection using the properties on button1. It assumes that button1 has been instantiated on a form.

[Visual Basic] 
Dim properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(button1)

[C#] 
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1);

[C++] 
PropertyDescriptorCollection* properties = TypeDescriptor::GetProperties(button1);

[Visual Basic, C#, C++] The next example prints all the properties on a button in a text box. It assumes that button1 and textBox1 have been instantiated on a form.

[Visual Basic] 
Private Sub MyPropertyCollection()
    ' Creates a new collection and assign it the properties for button1.
    Dim properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(button1)
    
    ' Displays each property in the collection in a text box.
    Dim myProperty As PropertyDescriptor
    For Each myProperty In  properties
        textBox1.Text &= myProperty.Name & ControlChars.Cr
    Next myProperty
End Sub 'MyPropertyCollection 

[C#] 
private void MyPropertyCollection() {
    // Creates a new collection and assign it the properties for button1.
    PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1);
 
    // Displays each property in the collection in a text box.
    foreach (PropertyDescriptor myProperty in properties)
       textBox1.Text += myProperty.Name + '\n';
 }

[C++] 
private:
    void MyPropertyCollection() {
        // Creates a new collection and assign it the properties for button1.
        PropertyDescriptorCollection* properties = TypeDescriptor::GetProperties(button1);

        // Displays each property in the collection in a text box.
        System::Collections::IEnumerator* myEnum = properties->GetEnumerator();
        while (myEnum->MoveNext())
        {
            PropertyDescriptor* myProperty = __try_cast<PropertyDescriptor*>(myEnum->Current);
            textBox1->Text = String::Concat( textBox1->Text, myProperty->Name, S"\n" );
        }
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.ComponentModel

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: System (in System.dll)

See Also

PropertyDescriptorCollection Members | System.ComponentModel Namespace | PropertyDescriptor | TypeDescriptor

Show:
© 2014 Microsoft