I want to make a popup menu when i rightclick on a ListView Row

I just want it to say

Edit
[Seperator]
Delete

^^

Also how do i make a Sub Item a link to open a new form?

Dani AI

Generated

Brief summary: asked how to show a popup menu on right-click of a ListView row and make a subitem open a new form. was right to suggest using a hidden context menu that is displayed on right-click, and 's note about clearer titles is worth remembering. Below are concise, practical patterns for WinForms (VB.NET) and classic VB6 that make the menu appear only when a row is clicked and let a subitem act like a link.

VB.NET (WinForms) — use HitTest to find the item/subitem, select it, then show a ContextMenuStrip. The same HitTest result can be used to open a form when a specific subitem is clicked.

Private Sub ListView1_MouseDown(sender As Object, e As MouseEventArgs) Handles ListView1.MouseDown
    If e.Button = MouseButtons.Right Then
        Dim info = ListView1.HitTest(e.Location)
        If info.Item IsNot Nothing Then
            ListView1.SelectedItems.Clear()
            info.Item.Selected = True
            ContextMenuStrip1.Show(ListView1, e.Location)
        End If
    End If
End Sub

Handle the menu item click to create/show the form, passing SelectedItems(0).SubItems(index).Text as needed. To make a subitem behave like a link, detect left clicks with HitTest and open the form when info.SubItem matches the desired column.

VB6 — detect the right mouse button in the ListView MouseDown event, convert Twips to pixels, use HitTest to locate the ListItem and set li.Selected = True. Then display the hidden menu (the approach suggested by ) or call the Windows API if finer control is required.

Private Sub ListView1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Button = vbRightButton Then
        Dim pxX As Long, pxY As Long
        pxX = X / Screen.TwipsPerPixelX
        pxY = Y / Screen.TwipsPerPixelY
        Dim li As ListItem
        Set li = ListView1.HitTest(pxX, pxY)
        If Not li Is Nothing Then
            li.Selected = True
            ' display the hidden popup menu here
        End If
    End If
End Sub

Troubleshooting notes: ensure the ListView is in Details/report view for subitems, convert twips correctly in VB6, clear previous selection before selecting on right-click, and test both mouse and keyboard activation (keyboard shortcuts or double-click) for accessibility.

Recommended Answers

All 4 Replies

Reeciepoo, after 15 threads, with useless titles like
Help
Databases
Need help
HTMLWrapper
How do you
Noobie
How the hell
Annoying Network Issue
Network Configuration
Some help please
Recommendations
Changing Font
C++ Help
it's probably time to read the Rules, especially the Keep It Organized section.

Reeciepoo, after 15 threads, with useless titles like

Help

Databases

Need help

HTMLWrapper

How do you

Noobie

How the hell

Annoying Network Issue

Network Configuration

Some help please

Recommendations

Changing Font

C++ Helpit's probably time to read the Rules, especially the Keep It Organized section.

Fair enough. are all 15 that bad?

make a menu with the name MenuPopUp
set the visible prop. to false

now the menu only can be made visible by this command:
Call Me.PopupMenu(MenuPopup)

Just add the sub menu's as you like.
These will have their own event to add code.

Thank you PVBert

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.