在C#中,使用WinForms或WPF时,可以通过以下方法将TreeNode数据绑定到控件上:
WinForms:
TreeNode node = new TreeNode("Node Text");
node.Name = "Node Name";
treeView1.Nodes.Add(node);
label1.Text = node.Text;
WPF:
TreeNode node = new TreeNode("Node Text");
node.Header = "Node Name";
treeView1.Nodes.Add(node);
textBlock1.Text = (string)node.Header;
BindingList<TreeNode> bindingList = new BindingList<TreeNode>();
bindingList.Add(node);
treeView1.ItemsSource = bindingList;
textBlock1.Text = bindingList[0].Header;