Re: TypeConverter's do not work
From: Frank Hileman (frankhil_at_no.spamming.prodigesoftware.com)
Date: 02/28/04
- Previous message: Niki Estner: "Re: TypeConverter's do not work"
- In reply to: Niki Estner: "Re: TypeConverter's do not work"
- Next in thread: Niki Estner: "Re: TypeConverter's do not work"
- Reply: Niki Estner: "Re: TypeConverter's do not work"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 28 Feb 2004 15:07:35 -0800
There is no matching constructor in Unit. You will need one with a string
arg. But why the message boxes don't show up -- I suppose b/c it sees there
is no constructor, so it doesn't bother with TypeConverter.
Regards,
Frank
"Niki Estner" <niki.estner@cube.net> wrote in message
news:eowGW2k$DHA.1288@TK2MSFTNGP10.phx.gbl...
> Hi Frank,
>
> The code is more or less copied from the MSDN, so it's probably rather
> boring to you.
> I didn't post my control, since it is rather:
> - it uses the System.Windows.Forms.Design.ControlDesigner
> - it contains a "Unit" property and a collection containing "Unit"'s
> - the message boxes in the UnitTypeConverter never show
> I think DevStudio doesn't know what TypeConverter to use for my "Unit"
> class, but I thought the "TypeConverter" attribute would do that?
>
> Niki
>
> Code:
>
> using System.ComponentModel;
> using System.ComponentModel.Design;
> using System;
> using System.Globalization;
> using System.ComponentModel.Design.Serialization;
> using System.Windows.Forms;
>
> namespace Test
> {
> [TypeConverter(typeof(Test.UnitTypeConverter)), Serializable()]
> public class Unit
> {
> private string name;
> public string DisplayName { get { return name; } set { name = value; } }
> }
>
> public class UnitTypeConverter : TypeConverter
> {
> public UnitTypeConverter()
> {
> MessageBox.Show("Test0");
> }
> public override bool CanConvertTo(ITypeDescriptorContext context, Type
> destinationType)
> {
> MessageBox.Show("Test1");
> if (destinationType == typeof(InstanceDescriptor))
> return true;
> return base.CanConvertTo(context, destinationType);
> }
> public override object ConvertTo(ITypeDescriptorContext context,
> CultureInfo culture, object value, Type destinationType)
> {
> MessageBox.Show("Test2");
> if (destinationType == typeof(InstanceDescriptor) && value is Unit)
> {
> Unit u = (Unit)value;
> System.Reflection.ConstructorInfo ctor = typeof(Unit).GetConstructor(new
> Type[] {typeof(string)});
> if (ctor != null)
> return new InstanceDescriptor(ctor, new object[] {u.DisplayName});
> }
> return base.ConvertTo(context, culture, value, destinationType);
> }
> }
> }
>
>
> "Frank Hileman" <frankhil@no.spamming.prodigesoftware.com> schrieb im
> Newsbeitrag news:%2335bJsY$DHA.4072@tk2msftngp13.phx.gbl...
> > Hello Niki,
> >
> > Every time I had this problem, it was due to a lack of a typeconverter.
Or
> > the typeconverter might be incorrect. Try closing visual studio, all
> > instances, and restarting. If that doesn't help, post your converter.
> >
> > Regards,
> > Frank Hileman
> >
> > check out VG.net: www.vgdotnet.com
> > Animated vector graphics system
> > Integrated VS.net graphics editor
> >
> > "Niki Estner" <niki.estner@cube.net> wrote in message
> > news:uYzTELY$DHA.2516@TK2MSFTNGP11.phx.gbl...
> > > Hi there,
> > >
> > > I have a control that contains a collection of custom objects. I'd
like
> > them
> > > to be code-serialized like this:
> > > myControl.myCollection.AddRange(new MyType[] { ... });
> > > But I always get code like this:
> > >
> > >
> >
>
this.myControl.myCollection.Add(((MyType)(resources.GetObject("resource"))))
> > > ;
> > >
> > >
> >
>
this.myControl.myCollection.Add(((MyType)(resources.GetObject("resource1")))
> > > );
> > >
> > > My custom class "MyType" has the "Serializable" attribute, and a
> > > "TypeConverter" attribute.
> > > I've tried inserting a MessageBox.Show into the type converter, it
isn't
> > > even created.
> > >
> > > I know this question has been posted before.
> > > I have read the answers
> > > They do not work.
> > > I also found an MSDN article about the topic
> > >
> >
>
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/h
> > > tml/custcodegen.asp)
> > > The sample code does not work either.
> > > (Steps to reproduce: compile the "ButtonArraySample" solution; Insert
a
> > new
> > > form, insert a "ButtonArray" control into that form, add some items to
> the
> > > "Buttons" collection using the designer - the source code contains
> > > "resources.GetObject" initializations, instead of constructors)
> > > Why is this so?
> > >
> > > I'm using Visual Studio.net 2003 (Version 7.1.3088)
> > > .NET Framework 1.1.4322
> > >
> > > Any help would be appreciated!
> > >
> > > Niki
> > >
> > >
> >
> >
>
>
- Previous message: Niki Estner: "Re: TypeConverter's do not work"
- In reply to: Niki Estner: "Re: TypeConverter's do not work"
- Next in thread: Niki Estner: "Re: TypeConverter's do not work"
- Reply: Niki Estner: "Re: TypeConverter's do not work"
- Messages sorted by: [ date ] [ thread ]