How to get Explorer context menu in Winforms ListView?

I use Winforms ListView to display some files, but besides showing files such as explorer, I want to have the same right-click menu when you get when you right-click an item inside.

Is it possible? How to enable it for my ListView application?

+4
source share
3 answers

The only way I know is to use pinvoke and COM for this. I think the unmanaged API you want is SHCreateDefaultContextMenu () . After you do the interop done (check pinvoke.net first), you can do the interop for all other things required by DEFCONTEXTMENU . It will not be easy. Welcome to the country of PIDL.

+2
source

I'm really having trouble displaying a custom context menu with a right click: Erroneous behavior from ContextMenu

I was still a little different:

private void lstModules_MouseDown(object sender , MouseEventArgs e) { hitTest = lstModules.HitTest(e.Location); switch (e.Button) { case MouseButtons.Right: if (hitTest != null && hitTest.Item != null) { // right clicking an item in the listview selectedModule = hitTest.Item.Name; lstModules.ContextMenuStrip = mnuContext_OptionsA; } else { // right clicking in white area of listview lstModules.ContextMenuStrip = mnuContext_OptionsB; } break; } } 
+2
source

You will need the IContextMenu interface. Also see this very useful series .

+1
source

Source: https://habr.com/ru/post/1301981/


All Articles