AddWinPart error 'child' is not a child control of this parent.

AddWinPart error 'child' is not a child control of this parent.

Old forum URL: forums.lhotka.net/forums/t/726.aspx


kids_pro posted on Tuesday, July 25, 2006

Hi there,

I am having trouble with AddWinPart code.
I do follow PTracker foot print.
Any idea why I get this error message?
'child' is not a child control of this parent.

karl replied on Wednesday, July 26, 2006

I've had the same error. It seems to be caused by not setting the business object property that's contained within the control, before databinding kicks in. Example, opening the Project Edit Control without setting the Project property. Rocky passes the Project into the ProjectEdit Constructor, so its always set. I guess databinding doesn't like the mProject member variable being nothing when it executes

Me.ProjectBindingSource.DataSource = mProject

Karl.

 

kids_pro replied on Wednesday, July 26, 2006

Dear Karl,
You might be right.
However i did initialize my collection already.

private Orders _orderqueque= Orders.GetOrders();
public EditQueque() {
    InitializeComponent();
   
    _orderqueque.BeginEdit();
    ordersBindingSource.DataSource = _orderqueque;
}

kids_pro replied on Wednesday, July 26, 2006

I have resolved the problem by delete the UserControl and create a new one.

jdelano replied on Tuesday, August 08, 2006

FYI, I was having this exact same problem today, and narrowed it down to the Equal's override. As soon as I pulled that out, it worked fine. I only got the error when trying to show my form as an MDI child. Otherwise, it seemed to be fine.

John Delano

Will replied on Thursday, August 16, 2007

I encountered this problem while working on a demo application based on the ProjectTracker20cs example.

Calling AddWinPart(new MyObject()); threw a 'child' is not a child control of this parent exception.

Commenting out the public override bool Equals(object obj) method in WinPart.cs made the exception go away, but I'm uncomfortable with this workaround, and I wonder what it will break in the future.

Can someone please shed some light on a proper solution?

sholder replied on Saturday, February 09, 2008

Yes, this is an old post but the internet archives everything. :)

This appears to come from not overriding GetIdValue() in the user control which inherits from WinPart, if you check ProjectTracker you'll find that GetIdValue is overridden.

Shane

ryanwcox replied on Wednesday, October 11, 2006

This can be a symptom of not overriding GetIdValue

Try splicing in this code:

private System.Guid _id = System.Guid.NewGuid();

public override object GetIdValue()
{
  return _id;
}

Copyright (c) Marimer LLC