By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,238 Members | 1,746 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,238 IT Pros & Developers. It's quick & easy.

Adding a context menu to a treeview

P: n/a
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.
Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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.

--
Bela Istok
MVP C#
Caracas, Venezuela
"Aaron Queenan" <aq*********************@contingent.com.au> wrote in message
news:uW*************@TK2MSFTNGP12.phx.gbl...
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.

Nov 15 '05 #2

P: n/a
> 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.
Nov 15 '05 #3

P: n/a
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" <aq*********************@contingent.com.au> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
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.
Nov 15 '05 #4

P: n/a
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.
"Bela Istok" <be****@hotmail.com> wrote in message news:OF**************@TK2MSFTNGP10.phx.gbl...
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" <aq*********************@contingent.com.au> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
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.
Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.