Can a control have multi parents?
-
Hi every body, I have to forms, each form has a tree that is exactly the same with the other, the best way is to use one tree control for both form, but I realize that when you add a control to another parent, the former parent will remove it from it's Controls' list. You have any idea to solve my problem? Thanks a lot! Regards.
-
Hi every body, I have to forms, each form has a tree that is exactly the same with the other, the best way is to use one tree control for both form, but I realize that when you add a control to another parent, the former parent will remove it from it's Controls' list. You have any idea to solve my problem? Thanks a lot! Regards.
A Control can only be visible once, it has at most one Parent, and resides in at most one Controls collection. So it is fine to move a Control around in some cases: - from one tab page to the next when these pages belong to the same TabControl (hence at most one of them is showing), - from one modal dialog to the next (at most one of them showing again) but you can't reuse a Control in general. You would have to have two Controls, and use code to keep them synchronized. :)
modified on Saturday, April 11, 2009 1:25 PM
-
Hi every body, I have to forms, each form has a tree that is exactly the same with the other, the best way is to use one tree control for both form, but I realize that when you add a control to another parent, the former parent will remove it from it's Controls' list. You have any idea to solve my problem? Thanks a lot! Regards.
A control can have only one parent. There's nothing stopping you form removing the control from one parent's Controls collection and adding it to another though.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
A Control can only be visible once, it has at most one Parent, and resides in at most one Controls collection. So it is fine to move a Control around in some cases: - from one tab page to the next when these pages belong to the same TabControl (hence at most one of them is showing), - from one modal dialog to the next (at most one of them showing again) but you can't reuse a Control in general. You would have to have two Controls, and use code to keep them synchronized. :)
modified on Saturday, April 11, 2009 1:25 PM
Pity :( It's a MDI application, user can even move the MDI forms around and align them parallely to work together. Now I have many troubles synchronize them. Anyway, thanks for you answers, I can use them in some other cases.