TreeView用法值得總結一下,今天用到了,一時忘了怎樣執行選中節時間點事件。private void BindTreeView()
{
treeView1.LabelEdit = false;//不可編輯
//添加結點
TreeNode root = new TreeNode();
root.Text = "根節點";
//一級
TreeNode node1 = new TreeNode();
node1.Text = "1";
TreeNode node2 = new TreeNode();
node2.Text = "2";
//二級
TreeNode node11 = new TreeNode();
node11.Text = "11";
TreeNode node12 = new TreeNode();
node12.Text = "12";
TreeNode node21 = new TreeNode();
node21.Text = "21";
TreeNode node22 = new TreeNode();
node22.Text = "22";
//二級加入一級
node1.Nodes.Add(node11);
node1.Nodes.Add(node12);
node2.Nodes.Add(node21);
node2.Nodes.Add(node22);
//一級加入根
root.Nodes.Add(node1);
root.Nodes.Add(node2);
//
treeView1.Nodes.Add(root);
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
if (treeView1.SelectedNode != null)
{
MessageBox.Show(treeView1.SelectedNode.Text);
}
}
url:http://greatverve.cnblogs.com/archive/2012/02/03/winform-treeview.html
參考:C# WinForm TreeView改變選中節點顏色,失去焦點時選中節點仍突顯。