Listbox - disable Cut/Copy/Paste from specific cells

I need to be able to toggle the ability to cut/copy/paste for specific cells in a Listbox
So at any given moment these functions are available in SOME cells but not others

Note : ALL cells have custom CellBackGround Paint event . and a disabled CellTextPaint event… so what the user SEES may or may not be the actual CELL(x,y) content

How do you navigate between and select a cell? Can you disable those menuitems on mouseDown or however you navigate to the cell to “select” it?

  • Karen

The cell has to “operate” as normal… just when specified those 3 operations must be disabled…
So regardless of how the cell “got focus”

but that did give me an idea… CELLGOTFOCUS / CELLLOSTFOCUS might work

subclass listbox and implement editcut editcopy edit xxxx etc however you want

in conjunction with cell got focus etc you should be able to do things on a cell by cell basis

and make sure you make the cells you cant cut copy paste from not editable so you dont have to try & mess with the active cell (since you cant really)

perhaps I am brain-dead today…
but there are no events that indicate a cut/paste/copy has occurred… actually cut/copy are the main concerns… not really worried about “paste” after I thought about it for a bit.

the only way I can think would be to find the parent of the listbox, and the active menubar of that window and disable the appropriate menu items and re-enable them.

Not worried about activecell, as I am not using that … I’ve implemented a much cleaner version of my own…
but it is the CELL itself I am concerned about

They’re not events, they’re Menu Handlers. Hence Norman’s advice to make a subclass so you can implement them. Menu handlers are called in a hierarchy - control (subclass), window, app - the first one that implements a handler wins.

I realize they are menu handlers… which is why I said

but the menu handlers belong to the WINDOW not to the listbox. which is why I also said

since when (and how) does a CONTROL have a menu -handler? the menus belong to the WINDOW/APP not the controls

Always in control subclasses actually.

  • karen

Sigh… let me rephrase… yes you can add a menu-handler… but there is no access to the menu ITEM (cut/copy)
and yes I can insert a new Menubar… but again that menu bar cannot be associated directly to a control

Sigh… add a menu handler and type “EditCopy” into the name field. Trust us, it’ll just work.

There is an event called EnableMenuItems which you can use to enable/disable the menus as well.

But if the control has the focus, the menuhandler called first is the one in the subclass so you can control what it does…

Also you can enable or disable teh menu items for that event…

I see Greg beat me to it

uh… no

as a test I did the following

  • added a menu handler to the container control
  • named it EditCopy as suggested
  • in the CellClick of the Listbox in the Container I put “EditCopy.Enabled=false”
  • compiled
  • selected the contents of a cell
  • hit Command-C
  • then successfully pasted the contents into another App, which is what I am trying to disable

Note : the compile obviously did not complain… But as another test I DELETED the menu item… and the compiler STILL did not complain… So I don’t know which handler the CellClick thought it was dealing with

This is a CONTAINER CONTROL with an embedded Listbox and one other control

EnableMenuItems won’t apply here, as the code needs to determine Cut/Paste Status on CellFocus, regardless of any menu selections.

Hmmm… the menu items don’t seem to work in a listbox the way they work in a textfield. I couldn’t get one to fire on a listbox either. Works great in a textfield subclass (the way it should). Is this a bug? A limitation of listbox?

This seems to work…

		dim cb as new Clipboard
		cb.text=""

placed in the MOUSEMOVE event (the final version will have logic based on current cell)

I tried it in the CELLLOSTFOCUS, the Listbox LostFocus, the container Lost Focus but none of those ever fired

There is probably a bit of “overhead”… but it basically cancels any cut/copy event