custom property for checkbox

  • Thread starter Thread starter Rick
  • Start date Start date
R

Rick

Hi group,

I'm trying to inherit from the windows checkbox control. This is no
problem. My goal is to add a property that is based on an enum. When I
have an enum declared within the class, it works correctly, however,
my enum is declared in a referenced assembly. The form cannot load the
enum from the referenced assembly, it indicates that it can't load the
type.

using VB, VS2005.

Any thoughts on this one? I would like to not have to duplicate my
enum in this class.

Thanks,

Rick.
 
Hi group,

I'm trying to inherit from the windows checkbox control. This is no
problem. My goal is to add a property that is based on an enum. When I
have an enum declared within the class, it works correctly, however,
my enum is declared in a referenced assembly. The form cannot load the
enum from the referenced assembly, it indicates that it can't load the
type.

using VB, VS2005.

Any thoughts on this one? I would like to not have to duplicate my
enum in this class.

Thanks,

Rick.

Further investigation shows that this is by design, I guess...the
runtime is using System.Reflection.Assembly.GetType(...) to find the
type information of my enum...this method is only looking in the
currently executing assembly, which means it will never look in my
referenced assembly. This is a poor design, I hope that someone has an
indication as to how to get around this...

TIA. Rick.
 
runtime is using System.Reflection.Assembly.GetType(...) to find the
type information of my enum...this method is only looking in the
currently executing assembly, which means it will never look in my
referenced assembly. This is a poor design, I hope that someone has an
indication as to how to get around this...

Hi Rick!

You are right. The System.Reflection.Assembly.GetType method looks only in
the executing Assembly. You are using a static (shared) method from the
Assembly class. Of course the executing Assembly will handle this request
(who else?). This is neither a poor design, nor do I see any other way.

Are you able to get the Assemblyobject (the referenced Assembly), containing
the enum (If you have any object o, you can use o.Gettype.Assembly)? Then
you can use the gettype method from this assemblyobject. If you do not have
this reference, you can enumerate through all referenced assemblies by using
AppDomain.CurrentDomain.GetAssemblies

Greets
Daniel
 
Hi Rick!

You are right. The System.Reflection.Assembly.GetType method looks only in
the executing Assembly. You are using a static (shared) method from the
Assembly class. Of course the executing Assembly will handle this request
(who else?). This is neither a poor design, nor do I see any other way.

Are you able to get the Assemblyobject (the referenced Assembly), containing
the enum (If you have any object o, you can use o.Gettype.Assembly)? Then
you can use the gettype method from this assemblyobject. If you do not have
this reference, you can enumerate through all referenced assemblies by using
AppDomain.CurrentDomain.GetAssemblies

Greets
Daniel

Hi Daniel,

Thanks for your replay. I should clarify a few things. First, the
issue is only at design time. This is a custom property for a custom
inherited checkbox control where the datatype of the property is that
of an enum which is in a referenced assembly. The designer cannot load
the enum from a referenced assembly at design time. The result is a
design time form that is completely unusable. So, I should also
clarify further that what I meant to say when I said executing
assembly, I meant to say the assembly that contains the control. At
runtime, it seems to resolve the enum correctly. But, this really
needs to work at design time to be at all useful.

So far, the only workaround to this is to duplicate the enum within
the control or control's assembly, or to move the control into a
business assembly. Neither solution is desirable though the former is
teh most managable for my checkbox problem.

So far in my investigations, I maintain that this as either an
oversight by the dev team, or a realized limitation that is by design.

Rick.
 
Hi Rick
of an enum which is in a referenced assembly. The designer cannot load
the enum from a referenced assembly at design time. The result is a
design time form that is completely unusable. So, I should also
clarify further that what I meant to say when I said executing

I was not able to reproduce this. I created a new Project (a classlibary),
and added nothing else than an public enum. I added a second project (a
windows forms project) and added a reference to the first project. In the
winformsapp I added a new class, inherits from checkbox and added a public
property with the type of the external enum. After building the projectmap,
i added the new checkbox to a form and the designer shows my checkbox very
well, and I was able to modifie the testproperty in der propertygrid (and
the values of the enum are shown in the combobox).
Just to be 100% sure, I deleted the projectreference and set a new one,
directly to the dll ... also no problem.

Are you able to post a few lines of code, showing the problem?

greets

Daniel
 
Hi Rick


I was not able to reproduce this. I created a new Project (a classlibary),
and added nothing else than an public enum. I added a second project (a
windows forms project) and added a reference to the first project. In the
winformsapp I added a new class, inherits from checkbox and added a public
property with the type of the external enum. After building the projectmap,
i added the new checkbox to a form and the designer shows my checkbox very
well, and I was able to modifie the testproperty in der propertygrid (and
the values of the enum are shown in the combobox).
Just to be 100% sure, I deleted the projectreference and set a new one,
directly to the dll ... also no problem.

Are you able to post a few lines of code, showing the problem?

greets

Daniel

Hi,

The code is very simple. I am doing exactly what you did.

In assembly one:
public enum MyEnum
Yes
No
End enum

In winform project which references assembly one:
public class myCheckBox
inherits checkbox

public property Bla as Assembly1.MyEnum
get ...
set ..
end property

when dragging the checkbox onto the form, it works. But closing the
form and re-opening it in the design seems to be where the wheels fall
off for me. If this works for you, I will dig deeper. I also tried a
test application and reproduced it. I will try another.

Thanks for you time on checking into this.

Rick.
 
Hi Rick
when dragging the checkbox onto the form, it works. But closing the
form and re-opening it in the design seems to be where the wheels fall
off for me. If this works for you, I will dig deeper. I also tried a

After opening and closing the designer 20 times, I think it's working in my
side. No error, warning or other kind of problem. The checkbox behaves
exactly as it should and the designer shows form and checkbox correctly.

If I had to guess, I would say this is any kind of VisualStudio problem; If
you like I can send you my solutionfolder, so you can check it against your
enviroment.

btw: do you use vista (I had/have to fight against stupid designerprobs,
using vista)? ...

greets
Daniel
 
Back
Top