Listbox change row and RMB

I have 2 list boxes, changing row of the 1. listbox displays some data in the 2. listbox.
now if I do not change row but click the RMB (right mouse button) the change event fires again.

is that a normal behaviour of the change event by using the RMB on the same row ?

using 2020r2

You „change“ the selected row (even if it is the same one).

Just add a property IndexOfCurrentlyDisplayedRow to keep track of which data are shown (generally called a ‚flag‘ as it flags the current state), and check in your event if your clicked row is already being displayed.

thanks Markus,
So you are saying we have to keep track ourself if a row has really changed ? what a pity, my regards to Xojo …
will try to use a flag

This is the behaviour of Xojo‘s listbox. In fact no one expects to change the selection by clicking the LMB.

clicking the RMB on a listbox row should NOT trigger the change event of the listbox row fill stop.

I’m pretty sure it does this to support contextual menus. You can cancel it quite easily by using the MouseDown event handler:

Function MouseDown(x As Integer, y As Integer) Handles MouseDown as Boolean
  if IsContextualClick then Return True
End Function

Of course then he no longer has a Contextual Menu in the ListBox - not a good solution.

It may or may not be appropriate for his situation, that’s for him to decide.

How do I define a GOOD solution? One that does not cause more problems further down the line.

Anthony, you’re an MVP, so your word carries a bit more weight than others - for me that gives you the obligation to come up with GOOD solutions, not workarounds with (for beginners) unforeseen side effects. How many have to discover that “suddenly” their contextual menu no longer works before they get a good solution?

Which is why I made sure to mention that this was a result of supporting Contextual menus before making the suggestion I did. We’re getting off-topic, though. Please feel free to offer an alternative solution.

:man_facepalming: :roll_eyes:

I already did. I didn’t want to do the whole work for him but here it is:

Now THAT is the kind of GOOD solution that I would expect from an MVP …

I’m glad you were able to craft a solution to the original issue. Have a great night!

thank’s for all your help, I will try some recommendations.
But I still think a RMB should not trigger a change row event!

and by the way, not everybody is with Dropbox !!!

I tried your recommendation with the IsContextClick ( which I did not know, but who knows everything ) and that is working for me, thanks very much

I put it on top of the change row event of the listbox and returned true.
so far so good.
Now I have to do the same for all my list boxes which have a ContextualMenu …

does it happen because the listbox is inherited and handles the change event, but the base listbox handles the RMB ? you know what I mean ?

You don’t have to be with dropbox to download.

Also with Anthony’s solution you have to put the code into every single Listbox - and when there is a bug or Xojo changes something you have to change all of them.

With my subclass solution you just set the Listbox to the customised superclass, the code only exists ONCE in your app (so easy to maintain), and it plays nice with the context menu.

But suit yourself.

1 Like

@Markus_Winter , the link does not work anymore… say it has been deleted