Creating controls at design time: Error: 'child' is not a child control of this parent
I am just having a little problem with my custom control and its control designer.
My task:
Writing a control (derived from TableLayoutPanel) which has the following behaviour:
Afterwards they can drag other controls (TextBoxes, ListBoxes, etc.) from the Toolbox and drop them into my control. At this time, a control designer should ask the developer to enter a name for a Label, which belongs to the control dropped by the developer. Now, the Designer forces my control to redraw itself.
Redrawing:
The Control should create a specified amount of columns, set by a property. Within each column, a FlowLayoutPanel should host a different amount of TableLayoutPanels (each TableLayoutPanel has two Cells: one for the label at the left side and one for the dropped control on the right side)
Problem:
When I am trying this, I have to remove the dropped control from the controls collection of my written control and put it into the generated TableLayoutPanel (which I have to put into the FlowLayoutPanel etc) . Here I am getting the Error:
What could this be and how could I resolve it?
Is there any way of a little workaround or so?
I just tried to hook up the ComponentAdding Event of the designer and so preventing the control dropped by the developer (TextBox, etc) from being added to the controls collection of my control, but it doesn't work.
Also resetting the controls parent won't work.
Here's what I have done:// the current Column, the FlowLayoutPanel should be added to // running through the columns
int cur_Col = 0;
foreach ( ... ) {
fP.Dock = DockStyle.Fill;
fP.BorderStyle = BorderStyle.FixedSingle;
Controls.Add(fP, cur_Col, 0);
// running through the controls for each column
foreach( Control cin ... ) {
// each control is added to a TableLayoutPanel
// This Panel is added to the FlowLayoutPanel
fP.Controls.Add(tP);
// setting the Parent of the control and putting it into
// the controls collection of the TableLayoutPanel
c.Parent = tP;
tP.Controls.Add(c, 1, 0);
Control cLabel =new Label();
cLabel.Text = "some text";
tP.Controls.Add(cLabel, 0, 0);
}
cur_Col++;
Regards,
Harald K?stinger

