accessing TypeConverter from code

S

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
 
J

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


| 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
|
 
S

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
 
J

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


|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
| >
| >
| > | > | 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
| > |
|
 
S

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top