Home All Groups Group Topic Archive Search About

accessing TypeConverter from code

Author
15 Jun 2006 10:53 PM
swartzbill2000
Hello,

I have a TypeConverter for converting between this Enum and Strings.

Public Enum DeviceNameEnum
    dnNone
    dn2500
    dnMirror
End Enum 'DeviceNameEnum

The Strings are "None", "2500", and "Mirror". The conversion works in a
PropertyGrid. How can I access the TypeConverter to convert an instance
of the Enum to the corresponding String to put in a TextBox?
Bill

Author
16 Jun 2006 2:09 AM
Jay B. Harlow [MVP - Outlook]
Bill,
You can use something like:

        Dim converter As TypeConverter =
TypeDescriptor.GetConverter(GetType(DeviceNameEnum))

To get the converter, be certain to review the parameters to GetConverter...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


<swartzbill2***@yahoo.com> wrote in message
Show quoteHide quote
news:1150412009.308729.175030@p79g2000cwp.googlegroups.com...
| Hello,
|
| I have a TypeConverter for converting between this Enum and Strings.
|
| Public Enum DeviceNameEnum
|    dnNone
|    dn2500
|    dnMirror
| End Enum 'DeviceNameEnum
|
| The Strings are "None", "2500", and "Mirror". The conversion works in a
| PropertyGrid. How can I access the TypeConverter to convert an instance
| of the Enum to the corresponding String to put in a TextBox?
| Bill
|
Author
16 Jun 2006 2:56 PM
swartzbill2000
I fixed the problem by also applying the TypeConverterAttribute
directly to the Enum. Previously, the TypeConverterAttribute was only
applied to a public property in a class, which is what makes a
PropertyGrid work.
Bill

Jay B. Harlow [MVP - Outlook] wrote:
Show quoteHide quote
> Bill,
> You can use something like:
>
>         Dim converter As TypeConverter =
> TypeDescriptor.GetConverter(GetType(DeviceNameEnum))
>
> To get the converter, be certain to review the parameters to GetConverter...
>
> --
> Hope this helps
> Jay B. Harlow [MVP - Outlook]
> .NET Application Architect, Enthusiast, & Evangelist
> T.S. Bradley - http://www.tsbradley.net
>
>
> <swartzbill2***@yahoo.com> wrote in message
> news:1150412009.308729.175030@p79g2000cwp.googlegroups.com...
> | Hello,
> |
> | I have a TypeConverter for converting between this Enum and Strings.
> |
> | Public Enum DeviceNameEnum
> |    dnNone
> |    dn2500
> |    dnMirror
> | End Enum 'DeviceNameEnum
> |
> | The Strings are "None", "2500", and "Mirror". The conversion works in a
> | PropertyGrid. How can I access the TypeConverter to convert an instance
> | of the Enum to the corresponding String to put in a TextBox?
> | Bill
> |
Author
16 Jun 2006 10:50 PM
Jay B. Harlow [MVP - Outlook]
I understand the property grid looks at the property first, the type second.

So if you put the typeconverter on only the Enum it should work in both
places.

Although I have not tested the above...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


<swartzbill2***@yahoo.com> wrote in message
Show quoteHide quote
news:1150469762.497314.221940@i40g2000cwc.googlegroups.com...
|I fixed the problem by also applying the TypeConverterAttribute
| directly to the Enum. Previously, the TypeConverterAttribute was only
| applied to a public property in a class, which is what makes a
| PropertyGrid work.
| Bill
|
| Jay B. Harlow [MVP - Outlook] wrote:
| > Bill,
| > You can use something like:
| >
| >         Dim converter As TypeConverter =
| > TypeDescriptor.GetConverter(GetType(DeviceNameEnum))
| >
| > To get the converter, be certain to review the parameters to
GetConverter...
| >
| > --
| > Hope this helps
| > Jay B. Harlow [MVP - Outlook]
| > .NET Application Architect, Enthusiast, & Evangelist
| > T.S. Bradley - http://www.tsbradley.net
| >
| >
| > <swartzbill2***@yahoo.com> wrote in message
| > news:1150412009.308729.175030@p79g2000cwp.googlegroups.com...
| > | Hello,
| > |
| > | I have a TypeConverter for converting between this Enum and Strings.
| > |
| > | Public Enum DeviceNameEnum
| > |    dnNone
| > |    dn2500
| > |    dnMirror
| > | End Enum 'DeviceNameEnum
| > |
| > | The Strings are "None", "2500", and "Mirror". The conversion works in
a
| > | PropertyGrid. How can I access the TypeConverter to convert an
instance
| > | of the Enum to the corresponding String to put in a TextBox?
| > | Bill
| > |
|
Author
17 Jun 2006 3:42 AM
swartzbill2000
I did test it. What you suggest works. The PropertyGrid works if the
TypeConverter is only applied to the Enum, and not to the property.
Bill

Jay B. Harlow [MVP - Outlook] wrote:
Show quoteHide quote
> I understand the property grid looks at the property first, the type second.
>
> So if you put the typeconverter on only the Enum it should work in both
> places.
>
> Although I have not tested the above...
>
> --
> Hope this helps
> Jay B. Harlow [MVP - Outlook]
> .NET Application Architect, Enthusiast, & Evangelist
> T.S. Bradley - http://www.tsbradley.net
>
>
> <swartzbill2***@yahoo.com> wrote in message
> news:1150469762.497314.221940@i40g2000cwc.googlegroups.com...
> |I fixed the problem by also applying the TypeConverterAttribute
> | directly to the Enum. Previously, the TypeConverterAttribute was only
> | applied to a public property in a class, which is what makes a
> | PropertyGrid work.
> | Bill
> |
> | Jay B. Harlow [MVP - Outlook] wrote:
> | > Bill,
> | > You can use something like:
> | >
> | >         Dim converter As TypeConverter =
> | > TypeDescriptor.GetConverter(GetType(DeviceNameEnum))
> | >
> | > To get the converter, be certain to review the parameters to
> GetConverter...
> | >
> | > --
> | > Hope this helps
> | > Jay B. Harlow [MVP - Outlook]
> | > .NET Application Architect, Enthusiast, & Evangelist
> | > T.S. Bradley - http://www.tsbradley.net
> | >
> | >
> | > <swartzbill2***@yahoo.com> wrote in message
> | > news:1150412009.308729.175030@p79g2000cwp.googlegroups.com...
> | > | Hello,
> | > |
> | > | I have a TypeConverter for converting between this Enum and Strings.
> | > |
> | > | Public Enum DeviceNameEnum
> | > |    dnNone
> | > |    dn2500
> | > |    dnMirror
> | > | End Enum 'DeviceNameEnum
> | > |
> | > | The Strings are "None", "2500", and "Mirror". The conversion works in
> a
> | > | PropertyGrid. How can I access the TypeConverter to convert an
> instance
> | > | of the Enum to the corresponding String to put in a TextBox?
> | > | Bill
> | > |
> |