-1
我想點擊一個TreeView的子節點或父節點時打開一個表格:使用樹狀,點擊樹狀節點事件
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
TreeNode head = new TreeNode("HEAD");
TreeNode member = new TreeNode("MEMBER ");
TreeNode submember = new TreeNode("SUB-MEMBER");
private void Form1_Load(object sender, EventArgs e)
{
head.Nodes.Add(member);
member.Nodes.Add(submember);
treeView1.Nodes.Add(head);
treeView1.AfterSelect += new TreeViewEventHandler(treeView1_AfterSelect);
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
if (treeView1.SelectedNode == member)
{
MemberForm mf = new MemberForm();
mf.ShowDialog();
}
if (treeView1.SelectedNode == head)
{
HeadForm hf = new HeadForm();
hf.ShowDialog();
}
if (treeView1.SelectedNode == submember)
{
SubMemberForm sf = new SubMemberForm(); //is this way of checking that which node is clicked efficient???
sf.ShowDialog();
}
}
}
是的,這是完全有效的。你只是比較對象引用。 – Blorgbeard 2011-03-29 11:29:07
這是什麼問題? – 2011-03-29 11:38:41
嘗試通過編寫這個if(Treeview1.selectednode.text ==「Your Required Node」) – Dotnet 2011-03-29 12:05:35