Adding a context menu to a treeview

  • Thread starter Thread starter Aaron Queenan
  • Start date Start date
A

Aaron Queenan

How can I use the designer to add a context menu to a class which inherits
from a control, e.g. treeview, without adding the context menu to a form?

For example, to add a context menu with "Select All" and "Clear Selection"
to a checked list box?

Thanks,
Aaron Queenan.
 
The only way to add a ContexMenu it's to add the ContexMenu in the Form or
do it in code, or you can add a class that inherits from treeview, and add
the contex menu in your class in the designer.
 
The only way to add a ContexMenu it's to add the ContexMenu in the Form or
do it in code, or you can add a class that inherits from treeview, and add
the contex menu in your class in the designer.

Thanks, Bela. I've tried creating a class that inherits from treeview, and
adding the context menu, but for some reason, when I click "Edit menu",
either nothing happens, or the "null reference" error appears. Does it work
okay in your setup? Maybe my VC.NET 2003 installation is broken.

A similar question: I've managed to add the context menu to the treeview
using the old copy/paste methodology, but is there any way to make the
shortcuts work? For example, if I add Ctrl-A to select all items, it works
fine when the menu is popped up, but doesn't work otherwise. Without
handling each keypress event, is there any way to have the menu
automatically handle the shortcuts while the control is focussed?

Thanks,
Aaron.
 
Sorry, it's don't work well, I put a user control put the menu in the user control edit the menu, and later change the class from user control to ListView and work well, (I think it a little weird), I guest that it's better do it in code, that this way, but it's almost a way, the problem it's because ListView don't have a design surface.



The answer to your second question it's that for default the shortcuts in the context menu don't get called until the menu it's visible, you can put the shortcuts in a Main Menu Item, and it will work.


--
Bela Istok
MVP C#
Caracas, Venezuela
Aaron Queenan said:
The only way to add a ContexMenu it's to add the ContexMenu in the Form or
do it in code, or you can add a class that inherits from treeview, and add
the contex menu in your class in the designer.

Thanks, Bela. I've tried creating a class that inherits from treeview, and
adding the context menu, but for some reason, when I click "Edit menu",
either nothing happens, or the "null reference" error appears. Does it work
okay in your setup? Maybe my VC.NET 2003 installation is broken.

A similar question: I've managed to add the context menu to the treeview
using the old copy/paste methodology, but is there any way to make the
shortcuts work? For example, if I add Ctrl-A to select all items, it works
fine when the menu is popped up, but doesn't work otherwise. Without
handling each keypress event, is there any way to have the menu
automatically handle the shortcuts while the control is focussed?

Thanks,
Aaron.
 
Thanks, Bela.

Unfortunately, I can't put the menu into the main menu, because it's a dialogue box for an Excel Plug-in.

On the plus side, I've tried assigning the ContextMenu property of the TreeView control, which solves the right-click problems, and some of the accelerators work. Ctrl-A works for selecting all, but Del doesn't work for some reason.

Aaron.
Sorry, it's don't work well, I put a user control put the menu in the user control edit the menu, and later change the class from user control to ListView and work well, (I think it a little weird), I guest that it's better do it in code, that this way, but it's almost a way, the problem it's because ListView don't have a design surface.



The answer to your second question it's that for default the shortcuts in the context menu don't get called until the menu it's visible, you can put the shortcuts in a Main Menu Item, and it will work.


--
Bela Istok
MVP C#
Caracas, Venezuela
Aaron Queenan said:
The only way to add a ContexMenu it's to add the ContexMenu in the Form or
do it in code, or you can add a class that inherits from treeview, and add
the contex menu in your class in the designer.

Thanks, Bela. I've tried creating a class that inherits from treeview, and
adding the context menu, but for some reason, when I click "Edit menu",
either nothing happens, or the "null reference" error appears. Does it work
okay in your setup? Maybe my VC.NET 2003 installation is broken.

A similar question: I've managed to add the context menu to the treeview
using the old copy/paste methodology, but is there any way to make the
shortcuts work? For example, if I add Ctrl-A to select all items, it works
fine when the menu is popped up, but doesn't work otherwise. Without
handling each keypress event, is there any way to have the menu
automatically handle the shortcuts while the control is focussed?

Thanks,
Aaron.
 
Back
Top