Right-clicking and edit cell in Listbox not working right

I have a custom contextual menu option that opens a cell for editing in my listbox. It works great as long as you click on the row first, and the right-click and choose Edit. However, if you have a row selected and right click on another row (which then becomes selected), it still opens the old row up for editing. It’s like when you right-click the new row, it’s not really the active row, even though it’s highlighted. I tried adding this to the CellClick and Mousedown event, but nothing changed.

if IsContextualClick then
  ClickedRow = me.SelectedRowIndex
end

How do I make the row “really” be selected with a Right-Click, and not “superficially” selected.

In CellPressed, you’re passed the Row and Column. Save those and use them in your contextual menu code. And you’re right, both MouseDown and CellPressed occur before the selection is changed.

I’ll try that.

I found this also works in my edit code.

For XX As Integer = SCRIPT_LISTBOX.ListCount-1 DownTo 0 
  If SCRIPT_LISTBOX.Selected(XX) Then 
    MAIN.SCRIPT_LISTBOX.EditCell(XX,0)
    
  end
Next

You could have done so:
if IsContextualClick then me.SelectedRowIndex=Row

(which will highlight the row before showing the contextual menu)

Bingo!!!

Thanks!

Actually, I went back to my For/List.count loop I posted earlier. I found that with Arnaud’s approach, if someone clicked on the listbox outside of the rows, it would turn whatever row was last selected into edit mode. With the loop, everything works the way I’m expecting. Thanks for the advice. Always good to try options!