marfi95 wrote:
I have a form that has a left and right panel. In the left panel is a
treeview. The right panel I want to change dynamically based on the
type of node selected.
I've done much the same in an application recently.
What I'm doing is loading the treeview nodes through an XML file.
As part of each node in the XML, I'm using an attribute that
indicates the name of a sub form to load.
OK, with you so far ...
As part of all these little child forms,
Here we part company. Your "editors" want to be UserControls, either
inherited from a base class or implementing an Interface either of which
defines how /every/ editor should behave.
the main control is a panel, which I then assign its parent to the right
panel of the main form.
Hacking Parentage of Controls can be messy, especially across multiple
Forms. UserControls are far easier to work with.
I have the tree loaded fine with no problems. I found some code using
reflection that would load the form as an object,
Object <Variant.
You can't do much [at all] with an Object; you have to get (i.e. cast)
the loaded "Editor" into a Type that your "frame" application knows how
to deal with - either your Base class or Interface.
but I haven't figured out how to assign the panel fields parent
because it doesn't know the "type" of form.
The best you'll get out of the box is a "Forms.Form", which still isn't
particularly useful; you'd have to loop [recursively?] down through the
Controls collection[s] to find the panel you want.
==========
Actually, I took this idea a little further. ;-)
From my file, I load a collection of Objects that
(a) can appear in various arrangements in the TreeView and
(b) can be edited by clicking on one of them (in the Tree).
Each of my my "EditableObjects" exposes a "GetTreeNode" function, which
returns a pre-formatted TreeNode (text, image, etc.) to pop into the
Tree anywhere I need it. This TreeNode has a property that points back
to the /original/ object.
This combination allows me to clear and rearrange the Tree in as many
different groupings as I need.
My "EditableObject" also exposes a "GetEditor" function, that returns a
UserControl (implementing my "IPluginEditor" Interface and) that
contains all the stuff I need to edit that /particular/
"EditableObject". All neatly self-contained.
The only code needed in the "frame" application is for the TreeView to
detect a Treenode from one of my "EditableObjects" (by its Type), get
the object itself (from the Property) and from that get it's "Editor"
and re-Parent that "Editor" into the right-hand panel.
More or less. :-)
HTH,
Phill W.