0

I have a ListView with some items. The ListView has some group defined, some column, and some items are added. The ListView has set also the ContextMenu.

On Opening event of the ContextMenu, I shall check whether the context menu was opened on a ListView item. So, I did:

private void CtxMenuProcess_Opening(object sender, CancelEventArgs e)
{
    ContextMenuStrip ctxMenuStrip = (ContextMenuStrip)sender;
    ListViewHitTestInfo hitTestInfo = LstViewAdminApp.HitTest(LstViewAdminApp.PointToClient(Control.MousePosition));

    if (hitTestInfo.Item != null) {
        //....
    }
 }

Sadly, the hit doesn't happen.

I feel that the coordinates of the ctxMenuStrip are the wrong ones, but I tried a lot of "variants" without success, and the documentation of ListView.HitTest is very poor.

Anybody can help me?


Further investigation doesn't bring any solution. I'm starting to suspect about ListView control initialization. Here is the non default properties I have set:

  • Activation = OneClick
  • Columns = Colum[3]
  • ContextMenuStrip = ContextMenu
  • Dock = Fill
  • FullRowSelect = true
  • GridLines = true
  • Groups = Group[3]
  • HideSelection = false
  • LabelWrap = false
  • Sorting = Ascending
  • View = Details
Luca
  • 11,646
  • 11
  • 70
  • 125

1 Answers1

0

When I was working on something like this a while back, I found the code in this example to be very useful.

THE DOCTOR
  • 4,399
  • 10
  • 43
  • 64
  • Thank you, but I can't use Windows messaging to solve my problem. The same code shall run also in Mono under Linux. – Luca Jan 02 '11 at 20:17