[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Adding menu in TreeView

Posted on 1998-10-14
5
Medium Priority
?
199 Views
Last Modified: 2010-04-30
Hi,

I want to add a context menu in a treeview. The menu will vary depending on the item I will click on (like in the Windows Explorer). I have found no reference to do that. Anyone can give mee a clue?
0
Comment
Question by:pjroy
  • 2
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
vmano earned 120 total points
ID: 1439918
check out help on PopupMenu method. good explanation and examples.
0
 
LVL 2

Expert Comment

by:shchuka
ID: 1439919
There are two possible solutions:

1. (Not the most elegant, but the easiest to implement).  Create several menues at design time and at run time in MouseDown event of the TreeView decide which one to display.

2. (A lot more elegant, but requires more programming.)  Create only one menu, say mnuPopup.  Create one item under it with empty caption, name it mnuDynamic (for examle) and set its index to 0, so that its a menu control array.  Also set this item's visible to false.  At run time, determine what items you need and do the following (suppose, the array MenuCaptions(1 to n) contains Captions of the menu items you need):

dim i as integer
for i=1 to n
    load mnuDynamic(i-1)
    mnuDynamic(i).caption = MenuCaptions(i)
    mnuDynamic(i).visible = true
next i

In the click event of mnuDynamic you will need to analyze the caption of the item clicked and do the stuff that you need to do.  After that, unload the items again:

private sub mnuDynamic_Click(index as integer)
    dim capt as string
    dim i as integer

    capt = mnuDynamic(index)
    if capt = val1 then
        ' Do something here
    elseif capt = val2 then
        ' Do something here
...
    end if

    for i=ubound(mnuDynamic) to 0 step -1
        mnuDynamic(i).visible=false
        unload mnuDynamic(i)
    next i
end sub

And finally in the MouseDown event of the TreeView you'll check what items you need to have in the menu, create them and do
    PopupMenu mnuPopup

Also you need to check if the menu was canceled and unload the items.  I believe you can do that from MouseUp event of the TreeView.

Hope this helps,
-Aleks.
0
 

Author Comment

by:pjroy
ID: 1439920
Adjusted points to 30
0
 

Author Comment

by:pjroy
ID: 1439921
How do I unload a menu loaded with PopupMenu?

When I right click at another place, I want the menu to be closed and reopened a new one.
0
 
LVL 3

Expert Comment

by:vmano
ID: 1439922
When you right click, just specify the X, Y coordinates for the popupmenu. this will take care when you click at another place.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question