Handle the AfterSelect event of the tree view and perform any necessary operations on the panel in code.
// Initialize the tree view (or let the designer do this for you):
public Form1()
{
TreeView tree = new TreeView();
tree.Dock = DockStyle.Left;
// Add a handler for the AfterSelect event:
tree.AfterSelect+= new TreeViewEventHandler ( TreeNodeSelected );
Controls.Add(tree);
Panel view = new Panel();
view.Dock = DockStyle.Fill();
Controls.Add(view);
}
// Handle the AfterSelect event:
private string currentViewType = null;
private void TreeNodeSelected(object sender, TreeViewEventArgs e)
{
/*
I'm assuming that viewType1 and viewType2 are instances of UserControl-derived classes.
If you have a view for each node type, you can create a UserControl for each view that may be displayed.
I also used a global-scope variable named, "currentViewType" that keeps track of the currently displayed view.
When you add Node objects to the "tree", make sure to set the "Node.Tag" property to the appropriate view type
name to be displayed.
For simplicity I used currentViewType as a string although an enumeration would make more sense if the node
types cannot be changed at runtime.
If you need more info for each Node other than just it's view type, you can set the Tag to a custom structure or class
that holds more information about the Node.
*/
if (e.Node.Tag == currentViewType)
return;
currentViewType= e.Node.Tag as string;
// 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);
break;
case "Type2":
view.Controls.Add(viewType2);
break;
}
}
--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Macca" <Ma***@discussions.microsoft.com> wrote in message news:9E**********************************@microsof t.com...
Hi Dave,
Thanks for the info.
How do i syncronise the treeview and panel?
i.e when i select an option on the treeview the panel should change to the
appropriate view.
Cheers
Macca
"Dave" wrote:
Add a TreeView to the Form and set it's Dock property to DockStyle.Left.
Add a panel or a single control that will display the properties such as a DataGrid to the Form and set it's Dock property to
DockStyle.Fill.
The splitter can be used if you want the TreeView to be resizable at runtime.
--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Macca" <Ma***@discussions.microsoft.com> wrote in message news:A2**********************************@microsof t.com... > Hi,
>
> I am developing an app which i want to have same style of GUI as the .NET
> Configuarion tool. i.e menus at top,rest of dialog dialog split into two with
> a tree like structure on the left and when item is selected on it, its
> contents are displayed on the right hand side.
>
> I'm not sure how to achieve this( maybe using splitter control with treeview)
>
> I'd appreciate any suggestions that could help me do the above
>
> Thanks In Advance
> Macca