Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add menu by right clicking listview row item?

Status
Not open for further replies.

Edward07

Programmer
Apr 13, 2007
49
NL
Hi all. could any one show me how i can add menu by right clicking listview item and be select an item and it opens new winow. I be happy if some one show me how this can be done.Thanks
 
Look at the popup menu in help. Something like this:

Code:
''Create a menu and call it mnuPop
''The top menu's Visible = False
''Enter your menus
''This can be done on the fly, but for sake of 
''brevity, I'll show my own examples.
''Each Index of the menu calls a different 
''set of procedures, as shown in the example
''Although I don't show these procedures, you
''can probably figure out what each routine does.
''============================================

''This procedure ascertains which menu was clicked
Private Sub mnuPop_Click(Index As Integer)
    Select Case Index
        Case 0
            Unload Me
        Case 1
            BegDate = Start2
            EndDate = End2
            OpenXL
            OpenSheets
            SaveAsFile
            QuitXL
            'SendEMail
        Case 2
            BegDate = Start1
            EndDate = End1
            OpenXL
            OpenSheets
            SaveAsFile
            QuitXL
            'SendEMail
        Case 3
            Visible = True
    End Select
End Sub

''This procedure checks to see what button was pushed
Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  
  If Button = 2 then ''Right button clicked
        Me.PopupMenu mnupopup
  End if
End Sub

I hope this helps.

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Thanks for you reply. I created menu using menu editor as shown in pic but i don't know how to make
it visible when i right click listview item so i be able to select items.Now the menue is in the top
of form!!Could u tell me what i am doing wrong? I keep right clicking and nothing happens.Furthermore,
how to link menu sub items to diffrent forms?



Code:
Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
 If Button = 2 Then PopupMenu mnuName

End Sub

Private Sub mnuName_Click()
  MsgBox ListView1.SelectedItem.Text
End Sub
This is the type of menue i want:
6d24d1e2f3.gif


This how i made menu:

a13a885ac1.jpg
 
I think that you need to find the point of the cursor, or CurX, CurY to make it popup where you want it.'

I hope this helps.

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.
 
Thanks. I fixed that problem. Now i don't know how to link my menu items to diffrent forms!!
 
Ok, to fix your problem, you had to make your menu item invisible, which is a bit counterintuitive.

I'm not sure what you mean by link menus to different forms. However, if what you'd like to do is show a menu that's specified on a different form from the one you're on, it's very simple:
Code:
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbRightButton Then
    PopupMenu Form1.mnuItem1
End If
End Sub

The point is that all you have to do is specify the name of the other form (in this case Form1; this proc is on a form called Form2) that has the menu item.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top