Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ExpandableObjectConverter Class

Provides a type converter to convert expandable objects to and from various other representations.

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

public class ExpandableObjectConverter : TypeConverter
public class ExpandableObjectConverter extends TypeConverter
public class ExpandableObjectConverter extends TypeConverter
Not applicable.

This class adds support for properties on an object to the methods and properties provided by TypeConverter. To make a type of property expandable in the PropertyGrid, specify this TypeConverter for standard implementations of GetPropertiesSupported and GetProperties. Mark child properties with the NotifyParentPropertyAttribute to ensure correct behavior in a PropertyGrid control.

NoteNote:

You should never access a type converter directly. Instead, call the appropriate converter by using TypeDescriptor. For more information, see the examples in the TypeConverter base class.

For more information about type converters, see the TypeConverter base class and How to: Implement a Type Converter.

The following code example converts a variable of type Margins to a string variable.

string strM="1,2,3,4";
System.Drawing.Printing.Margins  m= new System.Drawing.Printing.Margins(1,2,3,4);
Console.WriteLine(TypeDescriptor.GetConverter(strM).CanConvertTo(typeof(System.Drawing.Printing.Margins))); 
Console.WriteLine(TypeDescriptor.GetConverter(m).ConvertToString(m)); 

String strM = "1,2,3,4";
System.Drawing.Printing.Margins m = new System.Drawing.Printing.
    Margins(1, 2, 3, 4);
Console.WriteLine(TypeDescriptor.GetConverter(strM).CanConvertTo(
    System.Drawing.Printing.Margins.class.ToType()));
Console.WriteLine(TypeDescriptor.GetConverter(m).ConvertToString(m));

The following code example demonstrates how to use the NotifyParentPropertyAttribute and the ExpandableObjectConverter class to create an expandable property on a custom control. This code example is part of a larger example provided for the NotifyParentPropertyAttribute class.

[TypeConverter(typeof(BorderAppearanceConverter))]
public class BorderAppearance
{
    private int borderSizeValue = 1;
    private Color borderColorValue = Color.Empty;

    [Browsable(true),
    NotifyParentProperty(true),
    EditorBrowsable(EditorBrowsableState.Always),
    DefaultValue(1)]
    public int BorderSize
    {
        get
        {
            return borderSizeValue;
        }
        set
        {
            if (value < 0)
            {
                throw new ArgumentOutOfRangeException(
                    "BorderSize",
                    value,
                    "must be >= 0");
            }

            if (borderSizeValue != value)
            {
                borderSizeValue = value;
            }
        }
    }

    [Browsable(true)]
    [NotifyParentProperty(true)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    [DefaultValue(typeof(Color), "")]
    public Color BorderColor
    {
        get
        {
            return borderColorValue;
        }
        set
        {
            if (value.Equals(Color.Transparent))
            {
                throw new NotSupportedException("Transparent colors are not supported.");
            }

            if (borderColorValue != value)
            {
                borderColorValue = value;
            }
        }
    }
}

System.Object
   System.ComponentModel.TypeConverter
    System.ComponentModel.ExpandableObjectConverter
       Derived Classes

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

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft