Windows Develop Bookmark and Share   
 index > Windows Forms Designer > EditorAttribute at runtime?
 

EditorAttribute at runtime?

Hi

I've a question about the System.ComponentModel.EditorAttribute...

I am currently using it to decorate a property within a class in my object model so that it will open with a custom UITypeEditor in a propertygrid.

Public Class MyDataClass

<Editor(GetType(MyCustomUITypeEditor ),GetType(UITypeEditor))> _

Public Property MyProperty

...

End Property

End Class

Public Class MyCustomUITypeEditor

Inherits UITypeEditor

' overridemethods as necessary to show a custom editing dialog

...

End Class

Public Class MyUIClass

PrivatemyDataObjectas new MyDataClass

Private myPropertyGrid as new PropertyGrid()

...

Public Sub EditInstance()

myPropertyGrid.SelectedObject = myDataObject

myPropertyGrid.visible = true

' and away editing we go...

End Sub

End Class

Now this works fine except that I actually want to write MyUIClass and MyCustomEditorin another assembly not referenced by my data model, but I can't do this as MyClass requires a reference to MyCustomEditor (which in turn requires a reference to MyUIClass). However good design dictates I shouldn't have a reference to myview/controller in my model classes and besides, I might also want to specify more than one UITypeEditor if I had more than one UI to edit this property - which can't be done with an attribute.

Iit possible to do something like the following?

Public Class MyUIClass

...

Public Sub EditInstance()

Dim myEditorAttribute as New EditorAtribute(GetType(MyCustomUITypeEditor ),GetType(UITypeEditor))

' need some reflection jiggery pokery here to attach the attribute - don't think this can be done...

myDataObject.Properties("MyProperty").Attributes.Add(myEditorAttribute)

myPropertyGrid.SelectedObject = myObject

myPropertyGrid.visible = true

' and away editing we go...

End Sub

End Class

If not by extending the attributes of the property at runtime, which I would presume to be impossible, is there some other way ofdoing this imperatively that I've missed?

Many thanks

Iain Mcleod

Iain Mcleod  Wednesday, July 16, 2008 3:33 PM
I am having the same problem you were having, did you ever find a solution?

Sam
EHCarleton  Tuesday, June 09, 2009 4:59 PM

You can use google to search for other answers

Custom Search

More Threads

• This forum has moved the week of 12/8/2008
• PROBLEM: ParentControlDesigner.AllowSetChildIndexOnDrop internal?
• User Control as Container
• Hoe to Not Allow User to Delete Custom Controls at Desgin Time
• Hooking Keyboard events from the DesignSurface
• PropertyGrid Adding EventsTab
• Help Need Power Point Rect Tracker Source Code in VC6 or VC7
• Hard to explain....but please read.
• Populating comboboxes from eachother
• how to debug a control as it's loaded into control/resource/forms editor