473,396 Members | 2,033 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,396 software developers and data experts.

TypeConverter.GetStandardValues

Hi,

what kind of object has this method to return?

Generally the MSDN says return a list of the original data types. If it
comes to an example the instruction says return a list of strings. But
then the code example (in most cases an array of ints) returns a list
of ints. Unfortunately ints are implicitly castable to string.

So let's take an more un-obvious example. Lets say I have a class
Hotzenplotz and I want to have a TypeConverter. Hotzenplotz is
convertible from and to int and string.

Does GetStandardValues return a list of Hotzenplotz or a list of
string?

IMHO a list of Hotzenplotz, if you need it converted to string (e.g.
for an UI) one has to call ConvertTo(hotzenplotzObject,
typeof(string)).

Am I right or wrong?

Sep 21 '06 #1
5 5709
Well according to the below, it expects strings, but I've generally returned
typed items. When the PropertyGrid uses it, it calls ConvertTo [string]
anyway... it then calls ConvertFrom [string] afterwards to get back your
item. Presumably this is to support combo-style usage. A custom caller could
presumably just use the native objects themselves in a drop-down (not
combo), and rely on the .ToString().

http://msdn.microsoft.com/library/de...econverter.asp

<quote>
* Override the GetStandardValuesSupported method and return true.
* Override the GetStandardValues method and return a
StandardValuesCollection containing the standard values for the property
type. The standard values for a property type must be of type string.
* Override the CanConvertFrom method and return true for a sourceType
parameter value of type string.
* Override the ConvertFrom method and return the appropriate value for the
property based on the value parameter.
</quote>

Marc
Sep 21 '06 #2
Hi,

Marc Gravell schrieb:
Well according to the below, it expects strings
http://msdn.microsoft.com/library/de...econverter.asp

that's my point: It says it expects strings, but the code sample
returns ints:
values = new ArrayList(new int[] { 1, 2, 3, 4, 5 });
StandardValuesCollection svc = new StandardValuesCollection(values);

Sep 21 '06 #3
Hi,

Marc Gravell schrieb:
Well according to the below, it expects strings
http://msdn.microsoft.com/library/de...econverter.asp

that's my point: It says it expects strings, but the code sample
returns ints:
values = new ArrayList(new int[] { 1, 2, 3, 4, 5 });
StandardValuesCollection svc = new StandardValuesCollection(values);

Greetings,
Karsten

Sep 21 '06 #4
Looks like our instincts were right and the original docs were wrong; in
MSDN2:

http://msdn2.microsoft.com/en-us/library/ayybcxe5.aspx

<quote>
3. Override the GetStandardValues method and return a
StandardValuesCollection containing the standard values for the property
type. The standard values for a property must be of the same type as the
property itself.
</quote>

Sorted?

Marc
Sep 21 '06 #5
Hi,

Marc Gravell schrieb:
Sorted?
No, I'm very untidy. ;-)

Thanks!

Karsten

Sep 21 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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: David J | last post by:
Hi, I am trying to use the property grid in an app I am creating. I am currently using the examply I got from the codeproject site with the propertybags, if that rings a bell. I have created a...
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...
0
by: taskswap | last post by:
I've successfully set up a PropertyGrid using custom editors and type converters. They work very well. However, I have a spot where I want to generate the TypeConverter converter entries on the fly...
2
by: RedLars | last post by:
Hi, Trying to get an handle on the property grid which I'm finding very handy. I got one problem though that I have not been able to fix. Here is a small example to illustrate the problem;...
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...
1
by: Tomy Rodrigue | last post by:
Hi everyone, I display some data in a propertygrid using different TypeConverters that I created. Those TypeConverters have different behaviors but they all support the Mouse wheel event to change...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.