Control Designer & Child Controls Issue
-
Does anyone have a solution to this problem: :confused::confused::confused: When implementing a ControlDesigner or ParentControlDesigner, if one has a UserControl that contains child controls as follows: +========UserControl=========+ | +-----------------------------------+ | | | Caption Panel | | | +-----------------------------------+ | | +---------------------------------- + | | | Content Panel | | | +-----------------------------------+ | +=========================+ My desire is to have ToolboxItems that are added to the UserControl at design-time be added as children of the ContentPanel. - Using a ControlDesigner and invoking CreateComponent() adds the control to the current design document (the UserControl). - If one attempts to "re-parent" the control being "dropped" within the designer for the UserControl by doing the following Control target = ((myUserControl)this.Control).ContentPanel; // the (child) Control where the dropped control should be moved-to this.Control.Controls.RemoveAt(this.Control.Controls.IndexOf(ctl)); // remove the control from the UserControl (top-level parent) ctl.Parent = target; // assign the .Parent property of the control target.Controls.Add(ctl); // add the dropped control to the ContentPanel Controls collection The error "Object reference not set to an instance of an object" occurs. Do I need to create a(nother) designer for the ContentPanel so that IT can serve as the target of the DragDrop? Is there some other (more expedient) way to do this? Initiate an additional DesignerTransaction that makes the re-parenting change? Making the .Parent and Controls[] change, and then using the ComponentChangeService to make Changing/Changed notifications on the "Parent" and "Controls" PropertyDescriptors ?