Hi,
Thanks for your post.
You can drag two ContextMenuStrip to the form, one has an "Add Student" menu item, and the other has two menu items for adding student details. And handle the NodeMoustClick event to show the proper context menu according to the node selected, something like this
Code Snippet
treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
this.treeView1.SelectedNode = e.Node;
if (e.Node.Parent == null) //click on the root
{
this.contextMenuStrip1.Show(this.treeView1,e.Location);
}
else if (e.Node.Parent.Parent == null)//click on the student nodes
{
this.contextMenuStrip2.Show(this.treeView1,e.Location);
}
}
}
int studentCount = 1;
private void addStudentToolStripMenuItem_Click(object sender, EventArgs e)
{
this.treeView1.SelectedNode.Nodes.Add("Student" + studentCount.ToString());
studentCount++;
}
private void firstNameToolStripMenuItem_Click(object sender, EventArgs e)
{
this.treeView1.SelectedNode.Nodes.Add("First Name");
}
private void lastNameToolStripMenuItem_Click(object sender, EventArgs e)
{
this.treeView1.SelectedNode.Nodes.Add("Last Name");
}
Hope this helps. If you have any more questions, please feel free to let me know.Thanks in advance for any feedback.
Best Regards Zhi-xin Ye
|