listbox.activecell contextual menu ?

I try to install a contextual menu in a listbox when the user is editing a cell.
I install with addhandler a method that replaces the contructcontextualmenu event of the activecell, where I add items to the contextualmenu
I do this in the cellgotfocus event of the listbox

but when I right-clic an editable cell, I only have the 3 menus copy paste and clear of a standard textedit cell.
what did I miss ?

ConstructContextualMenu does not fire upon right click in the editor while a cell is edited.

A declare maybe possible to suppress the normal edit menu, but otherwise, you could use this in MouseDown :

[code]Function MouseDown(x As Integer, y As Integer) As Boolean
system.debuglog str(IsContextualClick)

if IsContextualClick then

dim base as new menuitem

base.append(New MenuItem("Un"))
base.append(New MenuItem("Deux"))
base.append(New MenuItem("Trois"))

dim m as menuitem

m = base.popup

if m <> nil then
  select case m.Text
  case "Un"
    msgbox "uno"
  case "Deux"
    msgbox "dos"
  case "Trois"
    msgbox "tres"
  end select
end if

Return True

end if

End Function

I don’t call directly the listbox contructcontextualmenu event !
I add an handler to the constructcontextualmenu event of the textedit that is the activecell of the listbox
this event is never fired ?

stick a break point in your addhandler code & see if you ever hit it

oh and WHEN do you add the event handler
that may be relevant

What is the code of your addhandler ?

I did that and it does not get there.

[quote=278371:@Norman Palardy]oh and WHEN do you add the event handler
that may be relevant[/quote]
in the CellGotFocus event of the listbox

AddHandler me.ActiveCell.ConstructContextualMenu, AddressOf EditCellConstructContextualMenu AddHandler me.ActiveCell.ContextualMenuAction, AddressOf EditCellContextualMenuAction

That is what I thought. ConstructContextualMenu simply never fires.

You should try the workaround I posted.

so that’s a bug ?

It would appear that way. It does not fire for the ListBox itself in the first place.

Amazingly enough there are several reports already in Feedback for ListBox ConstructContextualMenu, but they were closed as unreproducible. For my part I have never seen it fire.

It is possible that the whole thing is related, or not.

Edit : After a bit more experiments, it appears other events simply don’t fire for ListBox.ActiveCell, like Keydown. I tried to place the addhandler in CellGotFocus as well as in ListBox.Open, same difference.

Yet, I verified this object does have a handle, and it is not nil.

I was able to catch keydown, but I watched “cmd-v” to intercept paste
and in fact the system paste event is fired first, before my event and you can’t intercept
if you try to catch an event that is not catched by the system then you get it.

so I tried to do it another way by implementing contextualmenu, and it seems not possible too ?
what can you do then with activecell if you can’t intercept any event …?

Cmd-V is catched by the menu bar.

yes and we saw some times ago that if you name the menuitem other than “Paste” or “Coller” in french, then you can intercept it
otherwise, it is system catched and you cannot intercept it…

I want basically to paste an array of values coming from a spreadsheet into a list box
if you simply paste, then all the text is pasted in one cell
I want to paste an array of values into an array of listbox cells
I did it with a simple pushbutton, it works, now I want to intercept the paste and do it in a transparent way
if there is an array of values, paste it as an array, if not paste it the system way.

Long ago, when I spent a whole afternoon compiling on the Harris of the American Center of Paris, a friend of mine told me how he spent a few days on an Apple II ram disk project and never succeeded, because he was trying to low in the system. until he realized all what was needed was simply patching the UI (actually the crude Dos command system of the era) .

Instead of going at the cell level, stay at the menu level.

Sub CellGotFocus(row as Integer, column as Integer) EditMenu.item(4).name = "EditColle" End Sub

Sub CellLostFocus(row as Integer, column as Integer) EditMenu.item(4).name = "EditPaste" End Sub

Menu handler where to put the code you have in a button :

Function EditColle() As Boolean msgbox "Colle" Return True End Function

Et voil !

When the cell is edited, this renames the paste item which then points to EditColle menu handler. Then when the cell loses focus, paste reverts to its own self.

You want to stop the edition before you modify the content of the cells.

Peeked into the framework code & spoke quickly with Joe
I dont think this is possible given how things work internally
You’d need a “CellStartedEditing” event or something and use that to hook into the fields handlers at that point

:slight_smile: so it’s a “not yet implemented” feedback ?

a feature request would be in order

[quote=278467:@Michel Bujardet]Menu handler where to put the code you have in a button :

Function EditColle() As Boolean
msgbox “Colle”
Return True
End Function[/quote]
did you try it because I can’t make it work.
it seems the menuhandler has not been defined in any menubar, so it does not get called.
I must enable it so the name has really been changed, but it still seems to be not interceptable !

in fact it’s more complicated than that…
if I edit a cell, then I have a “paste array” in the text on the editpaste menu
but if I choose it, nothing happens, no msgbox, no system paste
if I go out of edit mode for the cell, then the msgbox “editpastearray” appears if I choose the editmenuitem
if I right clic the cell, then the system paste is executed.
so it seems the system paste is completely prioritary and you can’t do anything else.
I must make another “paste array” menu item under the “paste” menu item and deal with it separately
it seems impossible to intercept the editpaste menu item from the system calls