2

I have a TreeView in the left side of a SplitContainer and I would like the content on the right side to change when I click on a TreeNode. What I'm trying to do is a settings "window" such as the one in Putty, i.e. te content in the right side can be quite complex.

Putty
(source: unixwiz.net)

The idea I have is to have a panel for content for each tree node, add all those panels to the right side and show/hide them based on clicks on the tree view.

Is this the right approach? Is there a better one? What is the best way to link the tree nodes to with their panels, e.g some kind of MVC?

thank you

Tom

Community
  • 1
  • 1
scibuff
  • 13,377
  • 2
  • 27
  • 30
  • By far the simplest way to implement this in Winforms is with a TabControl, minus the tabs: http://stackoverflow.com/questions/2340566/creating-wizards-for-windows-forms-in-c-sharp/2342320#2342320 – Hans Passant Feb 18 '12 at 14:30
  • My blog post, [Implementing a Paged Options Dialog](http://www.differentpla.net/content/2004/10/implementing-a-paged-options-dialog), might give you some hints. The source code is [on github](https://github.com/rlipscombe/paged-options-dialog). – Roger Lipscombe Feb 18 '12 at 14:09

1 Answers1

3

You can have multiple panels with individual designers that accept a context object to fill or save the related settings Then in your TreeView you can use the Tag property of each node to maintain the related panel and when it is selected show the panel in right panel.

Here's some code :

interface ISettingPanel
{
SettingContext Context{get;set;}
}

public BasicSettingPanel:Panel,ISettingPanel
{
....
}

public void InitTreeView
{
var node=new TreeNode();
node.Tage=new BasicSettingPanel();// or you can set the type to create the panel later
treeView.Nodes.Add(node);
}

public void AfterNodeSelected()
{
_currentPanel=null;
var selectedNode=treeView.SelectedNode;
var panel=selectedNode.Tag as Panel;
if(panel!=null)
_currentPanel=panel;
(_currentPanel as ISettingPanel).Context=this.Context;
}
Beatles1692
  • 5,214
  • 34
  • 65