TypeConverter Question

  • Thread starter Dr. Guenther Schwarze
  • Start date
D

Dr. Guenther Schwarze

Hi,

Sorry for reposting, just thought to give it one more try, as this is a
really annoying problem for us. I will shut up if I still don't get any
replies this time <g>.

I have a component that has a class type property. This class in turn only
consists of about 20 public members which are of a certain enum type. What I
did is to derive a type converter from ExpandableObjectConverter. However,
as I don't want to supply a string representation for the whole class type
property in the property grid (what would this be for 20 members, if not
unreadable anyway?!), I didn't override any of the ConvertTo and ConvertFrom
methods but just have a derived, empty class. See the (shortened) code:

internal class EnumMemberClassConverter : ExpandableObjectConverter
{
}

....

[TypeConverter(typeof(EnumMemberClassConverter))]
public class ClassOfEnums
{
private MyEnum enum1;
private MyEnum enum2;
....
public MyEnum Property1
{
get/set enum1
}

public MyEnum Property2
{
get/set enum2
}

This doesn't seem to work - at design time I'm fine, I habe a property named
ClassOfEnums and can expand it. The sub properties can take on the values of
the enumeration. But the values set here are basically ignored at run time.
Do I _always_ have to provide a string representation? Or is the error
somewhere else? Any hints are very much appreciated.

Thanks very much,

G.
 
S

Shawn Burke [MS]

The TypeConverter won't be used at runtime. What's probably happening here
is that your values aren't being serialized. The first thing you can try is
adding a DesignerSerializationVisibilityAttribute:

public class MyComponent {


[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ClassOfEnums EnumProp {
//get/set
}
}

That tells the code generator that it needs to recurse into that property.
If that doesn't work, read through

http://www.msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotne
t/html/custcodegen.asp?frame=true

To get an idea of how it "should" serialize. If that doesn't work post to
microsoft.public.dotnet.framework.windowsforms.designtime
For this sort of thing.
 
D

Dr. Guenther Schwarze

Shawn Burke said:
The TypeConverter won't be used at runtime. What's probably happening here
is that your values aren't being serialized. The first thing you can try is
adding a DesignerSerializationVisibilityAttribute:

Shawn,

Thanks so much - this solved the problem. I think I would have searched for
a lifetime :)). Thank you!

G.
 

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