Dynamic Default Event Declaration

G

ge0193387

I'm dynamically adding controls to a custom control based on the data
type of the property being used.

So if the property is a string the control will be a groupbox
containing a textbox for entry of the string and a checkbox that I
would like to check on the textchanged event.

If the property is an enum I want the same items but instead of a
textbox I want a combobox to be filled with the enum values and the
event handler tied to the selected index changed.

To sum up I'm trying to find some property or attribute on a control
that will tell me what the default event is then create a handler for
that event at runtime.
 
N

Nicholas Paldino [.NET/C# MVP]

There isn't any metadata that is exposed by the controls to indicate
what the default event is (the designer class handles this). You are going
to have to mape these yourself.
 
M

Marc Gravell

Just an aside... you might want to look more into TypeConverter than
coding against specific rules... you can get a converter from the
PropertyDescriptor. For instance, if the type converter supports
standard values, it might be a drop-down (exclusive) or combo (non-
exclusive). I have quite a rich generic-editor using this and
supporting UITypeEditor, but it is too large for a post here. Various
people have done similar - for instance:
http://www.devx.com/DevX/Article/20920/0/page/3

Marc
 
M

Marc Gravell

There isn't any metadata that is exposed by the controls to indicate
what the default event is (the designer class handles this).

Does it not use TypeDescriptor.GetDefaultEvent(), as described by the
DefaultEventAttribute against the control?

(I haven't checked - I just assumed that it did)

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

Top