473,320 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

accessing TypeConverter from code

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
4 1685
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joăo Santa Bárbara | last post by:
Hi all i have a class that i have made and i made an Typeconverter as well, and my problem is the code genereated in my form is Dim ClassTest1 As TestApplication.ClassTest = New...
3
by: Norman | last post by:
I have a collection that can have a reference to various types of arrays. String was easy: ... string sPropertyArray = (string)oReturn; foreach( string sItem in sPropertyArray ) { ...
2
by: kw | last post by:
I'm getting different behavior from what I would expect and was hoping someone could clue me in. At run time I need to examine a property of an object for a custom TypeConverter, then use that...
5
by: ljlevend | last post by:
Is there a TypeConverter that converts Doubles to percent values in a PropertyGrid? The Windows.Forms.Form.Opacity property seems to use the TypeConverter that I want. Thank you, Lance
0
by: Alex Clark | last post by:
Hi all, Apologies for the cross-post but I can't determine if this is a VS .NET problem or a VB.NET language issue. I'm using .NET 1.1 SP1, VS 2003 EA, VB.NET. I'm coding a custom component...
4
by: Kent Boogaart | last post by:
*tried this already on the buildingcontrols newsgroup but didn't get a response* Hi, As far as I can tell, it is not possible to use the TypeConverter infrastructure with generic types. Say...
11
by: Rolf Welskes | last post by:
Hello, the problem seems to be complex and is in all developments of web-controls which uses own TypeConverter. For this I have here a simple demo-program of the problem: The Control-code: A...
1
by: --== Alain ==-- | last post by:
Hi, I 'm facing an interesting issue regarding a property and its TypeConverter. When i do not attach a TypeConverter to this property, all custom properties of my custom control are displayed...
6
by: Larry Smith | last post by:
Hi there, Can anyone provide any insight on why MSFT introduced "TypeConverter.GetProperties()". There are two classes for dealing with metadata in .NET, 'Type" and "TypeDescriptor". Each has a...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.