Hi Macca,
See inline comments below.
What i would like to be able to do is design these "views" at design time
through editor and not programatically if possible.
You can design each view as a control that derives from UserControl (this can be added using VS.NET as "Add New Item...", "User
Control" and will provide you with a designer).
Is what i am asking possible? Will i need to do something a bit different
from what you initially suggessted in using a panel control for the views?
In my example following this comment
// Initialize the tree view (or let the designer do this for you):
the view that is being added was not intended to hold view-specific controls but instead to be the container for "view" controls.
It's the variable name that threw you off. It should be called, "viewContainer". I mentioned UserControl in the large comment
found in the "TreeNodeSelected" method example and I did intend for you to make UserControl's as your views. The reason for the
panel is simply for ease of docking or if you wanted to control visual aspects of the view area such as a border. When a view is to
be shown (UserControl), it must be added to Controls collection of the "view" variable and not the parent Form. Changing the name
to viewContainer as I mentioned might make things clearer.
Then i assume as i select a node in the treeview i could invoke the
appropriate view as you have showed me.
This requires code, but yes my example should work nicely for you. Ensure that the "TreeNodeSelected" method I gave in my original
example is a handler for your TreeView's "TreeNodeSelected" event.
The purpose of setting the Tag property of each node is to associate the node with a view. This may be overkill for your needs but
I used it in the example to be dynamic. If you want to simplify the "TreeNodeSelected" to associate nodes with specific text to
specific views, the modified code could be changed to look like this:
private void TreeNodeSelected(object sender, TreeViewEventArgs e)
{
if (e.Node.Text == currentViewType)
return;
currentViewType = e.Node.Text;
// remove the current view
// here would be a good place to save any changes before the next line of code
view.Controls.Clear();
switch (currentViewType)
{
case "Type1":
view.Controls.Add(viewType1); // viewType1 is a referene to a UserControl instance that is one of your "Views"
break;
case "Type2":
view.Controls.Add(viewType2); // viewType2 is a referene to a UserControl instance that is one of your "Views"
break;
}
}
I hope that clears up some of the confusion with my code.
GL