I have a TreeView with parent node: Node0 . I add 3 subnodes :
Node01 Node02 Node03
I have a popup menu that is associated with each of the sub-pods.
My problem: if I right-clicked directly on one of the sub-bases, my pop-up window will not appear. So I need to first select Subnode and right-click to display a popup.
- How can I change the code so that Direct Right-Click on a specific SubNode opens PopupMenu?
- In popupMenu, there is only an
OpenMe menu in the list. When you click on this menu, the windows should open, and these windows should be associated with the submenu that I clicked. How to get an event in the right submenu with the right mouse button and display a 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); } }
Line String s = treeView1.SelectedNode.Text; gets the name of the selected node, not the node that was right-clicked.
So here I have to change this piece of code with
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 a 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
source share