I have a TreeView with the parent node : Node0. I add 3 subnodes:
Node01
Node02
Node03
I have a popup menu that is associate to each of the subnodes.
My problem: If I right-click directly to one of the subnodes, my popup does not display. So I have to Select the Subnode first and Right-click to have the popup displayed.
- How can I change the code so that the Direct Right-Click on a specific SubNode open the PopupMenu?
- The popupMenu have only
OpenMemenu in the list. When clicking on this menu, a windows is supposed to open and this windows should be associated to the submenu I have clicked. How to get the Event of the right-click submenu and display Form with it?
EDIT:
Look at this
private void modifySettingsToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
String s = treeView1.SelectedNode.Text;
new chartModify(s).ShowDialog();
}
catch (Exception er)
{
System.Console.WriteLine(">>>" + er.Message);
}
}
The line String s = treeView1.SelectedNode.Text; gets the name of the selected node and not the node that have been right-clicked.
So here I have to modify this piece of code with the
private void treeview1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Button == MouseButtons.Right)
MessageBox.Show(e.Node.Name);
}
I modify it like this:
try
{
TreeNodeMouseClickEventArgs ee;
new chartModify(ee.Node.Name).ShowDialog();
}
but it does not work : Error:Use of unassigned local variable 'ee'
EDIT #2: Finaly got the solution
public string s;
private void modifySettingsToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
new chartModify(s).ShowDialog();
}
catch (Exception er)
{
System.Console.WriteLine(">>>" + er.Message);
}
}
and then
private void treeview1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
s = e.Node.Name;
menuStrip1.Show();
}
}
it works,
Thanks