Contextual menu behaviour with listbox

I want to select multiple rows in a listbox and then right click to display a menu eg “Delete” to remove rows.
All good but when I choose the item on the menu the listbox goes back to a single selection.
Is it possible to delete rows this way or will I need an external control like a pushbutton to do it after selecting the rows?

I would prefer the right click option as there is a whole menu of operations I would like to perform on multiple rows at once. It’s neater and easy to expand the list later without using extra control real-estate.

You could keep a list of selected rows, which you reinstate in ConstructContextualMenu with Selected().

The concept sounds good but where do I put this code (below)?
It needs to before the menu is clicked but after the rows are selected.

[code]Dim selectedRows() As Integer // Will hold the index of each selected row

For row As Integer = 0 To ListBox1.ListCount - 1 // Rows are zero-based
If ListBox1.Selected(row) Then
selectedRows.Append row // This row is selected
End If
Next[/code]

Return True from the MouseDown event if it’s a right-click. This prevents the click action from being processed by the control and resetting the selection:

Event MouseDown(x As Integer, y As Integer) As Boolean
  If IsContextualClick Then
    Return True
  End If
End Function

[quote=294760:@Craig Grech]The concept sounds good but where do I put this code (below)?
It needs to before the menu is clicked but after the rows are selected.[/quote]

I have a few examples on the old website at drdakin.Tripod.com that you can download and see if this is what you would like to do.

I thought this would work but in the past I had to remove the “return True” to allow the contextual menu to fire on Mac. Works on Windows though.