Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Container Controls no longer accepting drag/dropped controls after a load
 

Container Controls no longer accepting drag/dropped controls after a load

When I drag a control onto my designer from the toolbox, it works great. I can add sub-controls etc. If I save and close the form, then reload it, all the panels/groupboxes etc do not accept controls being dropped onto them anymore, the controls simply drop to the main surface (behind the container control).

In my BasicDesignerLoader, in PerformLoad, I loop through my data and create my controls. I do something like the following:

Protected Overrides Sub PerformLoad(ByVal serializationManager As System.ComponentModel.Design.Serialization.IDesignerSerializationManager)

Dim component As IComponent = LoaderHost.CreateComponent(GetType(RootControl), "Form")
Me.SetBaseComponentClassName("Form")

'Load my data Object

Dim tempControl As someDataType
For Each tempControl In myDataObject.Controls
CreateControl(tempControl, CType(component, Control))
Next

Me.LoaderHost.EndLoad("UserControl", True, errors)
End Sub

Private Sub CreateControl(Byval controlObj as someDataType, ByVal parent as Control)
'Figure out the type

Dim newComponent as IComponent = LoaderHost.CreateComponent(myCtrlType, controlObj.name)
ctrl = CType(newComponent, Control)
ctrl.parent = parent

'Set the user entered properties

Dim tempObj as someDataType
For each tempObj in controlObj.Controls
CreateControl(tempObj, ctrl)
Next
End Sub


FBNitro  Wednesday, August 06, 2008 5:39 PM
I have the solution to this issue, but it leads to another.

I use reflection to copy the control properties, and when the call to TypeDescriptor.getProperties(myObject, Nothing, False) is made, instead of returning the results of my ICustomTypeDescriptor's properties, it's ignoring the custom type descriptor and giving me the entire list of properties. So, I ended up setting AllowDrop = false (ignore the details why).

Anyone have any idea why the ICustomTypeDescriptor would be ignored when I'm explicitly stating in the TypeDescriptor.GetProperties to use it?

FBNitro  Wednesday, August 06, 2008 6:57 PM

Hi,

Did you check http://msdn.microsoft.com/en-us/library/3bthc7h2(VS.80).aspx

I think you need to pass True.

Martin

Martin Thorsen - MSFT  Wednesday, August 06, 2008 8:13 PM
Yes, I considered that. I've tried both true and false just to be sure, but I do this throughout my code in other places and the documentation seems to have it backwards.

It should be:
True = Use DefaultTypeDescriptor
False = Use ICustomTypeDescriptor

FBNitro  Thursday, August 07, 2008 12:25 AM

You can use google to search for other answers

Custom Search

More Threads

• Inherit UserControl Exception
• PropertyDescriptor, IsBrowsable and the PropertyGrid
• Howto include designtime help for a component
• C# Active Directory Contact List
• Looking for a video manipulatingcomponent
• ComboBox Cell
• How to get key events in a controldesigner
• Visual Studio Designer will not render User Control
• ShouldSerialize and Rest
• [C++] how can i save graphic to an image file ?