TypeConverter.GetStandardValues

  • Thread starter Thread starter Karsten Schramm
  • Start date Start date
K

Karsten Schramm

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?
 
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/d...guide/html/cpconimplementingtypeconverter.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
 
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
 

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

Similar Threads


Back
Top