How do you disable a contextual menu that appears when you right click in a listbox


I have created a Contextual Menu with Items, but I want to make sure that if there are NO items in the listbox, it is disabled.

I have tried every mouse event I could find, but nothing works.

Any ideas.


You can get the row with RowFromXY and the. You just check if row = -1. That means the user is right-clicking on something that’s not a row.

You could also check to see if rowcount = 0.

Then all you do is not add any items but still return True.

Should be checking for -1 anyway. User might right-click after the last row in the listbox or in the scrollbar.

1 Like

That worked; thanks all.