I'm not sure how to display content in a Panel when the user clicks an item in the TreeView when there are multiple levels of items.
当有多个级别的项目时,当用户单击TreeView中的项目时,我不确定如何在Panel中显示内容。
I've seen this everywhere, but not sure where to start. Can someone please point me in the right direction?
我到处都看过这个,但不知道从哪里开始。有人可以指出我正确的方向吗?
2 个解决方案
#1
3
I typically use the tree's AfterSelect event handler such as:
我通常使用树的AfterSelect事件处理程序,例如:
private void tree_Detail_AfterSelect(Object sender, TreeViewEventArgs e)
{
swich (tree_Detail.SelectedNode.Name)
{
case "node1":
//display node 1 content in panel
break;
case "node2":
//display node 2 content in panel
break;
//...etc...
}
}
You could also use each tree node's Tag property (an Object) to store something such as an identifying Integer value and react to that instead of the text name. But I will usually just name the nodes prefixed with "node" so that I can react to them in a recognizable way in code.
您还可以使用每个树节点的Tag属性(Object)来存储诸如标识Integer值之类的内容,并对其进行响应而不是文本名称。但我通常只会命名前缀为“node”的节点,以便我可以在代码中以可识别的方式对它们做出反应。
#2
0
I figured it out:
我想到了:
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
switch(e.Node.Text)
{
case "General":
// Do something...
break;
// Etc...
}
}
#1
3
I typically use the tree's AfterSelect event handler such as:
我通常使用树的AfterSelect事件处理程序,例如:
private void tree_Detail_AfterSelect(Object sender, TreeViewEventArgs e)
{
swich (tree_Detail.SelectedNode.Name)
{
case "node1":
//display node 1 content in panel
break;
case "node2":
//display node 2 content in panel
break;
//...etc...
}
}
You could also use each tree node's Tag property (an Object) to store something such as an identifying Integer value and react to that instead of the text name. But I will usually just name the nodes prefixed with "node" so that I can react to them in a recognizable way in code.
您还可以使用每个树节点的Tag属性(Object)来存储诸如标识Integer值之类的内容,并对其进行响应而不是文本名称。但我通常只会命名前缀为“node”的节点,以便我可以在代码中以可识别的方式对它们做出反应。
#2
0
I figured it out:
我想到了:
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
switch(e.Node.Text)
{
case "General":
// Do something...
break;
// Etc...
}
}