By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,376 Members | 1,599 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,376 IT Pros & Developers. It's quick & easy.

accessing TypeConverter from code

P: n/a
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

Jun 15 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
<sw************@yahoo.com> wrote in message
news:11**********************@p79g2000cwp.googlegr oups.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
|
Jun 16 '06 #2

P: n/a
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
<sw************@yahoo.com> wrote in message
news:11**********************@p79g2000cwp.googlegr oups.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
|


Jun 16 '06 #3

P: n/a
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
<sw************@yahoo.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.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
| >
| >
| > <sw************@yahoo.com> wrote in message
| > news:11**********************@p79g2000cwp.googlegr oups.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
| > |
|
Jun 16 '06 #4

P: n/a
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:
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
<sw************@yahoo.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.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
| >
| >
| > <sw************@yahoo.com> wrote in message
| > news:11**********************@p79g2000cwp.googlegr oups.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
| > |
|


Jun 17 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.