I hav开发者_Go百科e a main user control with two panels. In one panel I have a tree view and in the other panel I want to load user controls.
I have created the tree view control but what I wanted was that when the links in the tree view are clicked the corresponding user controls should load in the second panel.
Can someone tell me how to achieve this?
You'd need to use the codebehind.
Have all the controls you need created on both panels, and in the codebehind, create a SelectedNodeChange event handler for the TreeView. In this event handler, you'd show/hide the controls you need at that point, and set the properties you need at that moment as well.
If you want to show/hide certain controls depending on the parent of a selected node: you can do something like this:
Say you have a treeview consisting of something like this
Ford
-Fiesta
-Mondeo
BMW
-316
-318
-320
And you want to show textBox1 ONLY IF a BMW model is selected, you'd do something like this in the event handler:
if (CarsTreeView.Parent.SelectedNode.Text == "BMW")
{
textBox1.Visible = true;
}
else
{
textBox1.Visible = false;
}
精彩评论