ListView control - Error when pressing escape key with any mouse event enabled

I'm trying to find out the issue with mouse events in the listview dotnet control and pressing escape.

At the bottom, is the code.

If you block out all the on lv <eventname>'s, then there's no error.

The only way to remove the error and keep the code is to add this:

  on lv KeyUp e do (
    if e.keyvalue == 27 do lv.dispose()
    --print (e.keyvalue as string + " - Escape KeyUp")
    )

Which isn't ideal.

Here's the full code, just run it and hit escape a few times for the JIT error to appear:

try(destroyDialog lvRol)catch()
clearListener()
rollout lvRol "ItemMouseHover - Help Required" height:300 width:500
(
  -- functions
  local _lvInit, _lvPopulateList, _lvAddColumns, _lvIsFormReadyToFocus
 
  dotNetControl lv "system.windows.forms.listView" height:(lvRol.height) width:(lvRol.width-1) pos:[0,0]
 
  fn _lvInit lvArg = (
    lvArg.view          = (dotNetClass "system.windows.forms.view").details
    lvArg.FullRowSelect = true
    lvArg.MultiSelect   = true
    )
 
  fn _lvPopulateList lvArg = (
    rows = #()
    for x in objects do (
      li = dotNetObject "System.Windows.Forms.ListViewItem" x.name
      li.tag = dotnetmxsvalue x
      li.subitems.add ((classOf x) as string)
      li.subitems.add (((x.wireColor) as point3) as string)
      append rows li
      )
    lvArg.items.addRange rows
    )
 
  fn _lvAddColumns lvArg columnsAr = (
    w = (lvArg.width/columnsAr.count)-1
    for x in columnsAr do  (
      lvArg.columns.add x w
      )
    )
 
  on lv MouseCaptureChanged do (print "MouseCaptureChanged")
  on lv MouseClick do (print "MouseClick")
  on lv MouseDoubleClick do (print "MouseDoubleClick")
  on lv MouseDown do (print "MouseDown")
  on lv MouseEnter do (print "MouseEnter")
  on lv MouseHover do (print "MouseHover")
  on lv MouseLeave do (print "MouseLeave")
  on lv MouseMove do (print "MouseMove")
  on lv MouseUp do (print "MouseUp")
  on lv MouseWheel do (print "MouseWheel")
 
  on lvRol open do (
    _lvInit lv
    _lvAddColumns lv #("Object", "Class", "Wire Color")
    _lvPopulateList lv
    )
 
  )
createDialog lvRol

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
3dwannab's picture

Narrowed down the problem

I've been revisiting this issue today and I've narrowed down the problem to the MouseDown event handler.

Removing this removes the error completely.

See line 45-48 of the below code.

try(destroyDialog lvRol)catch()
clearListener()
rollout lvRol "ItemMouseHover - Help Required" height:300 width:500
(
  -- functions
  local _lvInit, _lvPopulateList, _lvAddColumns, _lvIsFormReadyToFocus
 
  local _uiKbAltDown = off
  local _uiKbMouseDown = off
 
  dotNetControl lv "system.windows.forms.listView" height:(lvRol.height) width:(lvRol.width-1) pos:[0,0]
 
  fn _lvInit lvArg = (
    lvArg.view          = (dotNetClass "system.windows.forms.view").details
    lvArg.FullRowSelect = true
    lvArg.MultiSelect   = true
    )
 
  fn _lvPopulateList lvArg = (
    rows = #()
    for x in objects do (
      li = dotNetObject "System.Windows.Forms.ListViewItem" x.name
      li.tag = dotnetmxsvalue x
      li.subitems.add ((classOf x) as string)
      li.subitems.add (((x.wireColor) as point3) as string)
      append rows li
      )
    lvArg.items.addRange rows
    )
 
  fn _lvAddColumns lvArg columnsAr = (
    w = (lvArg.width/columnsAr.count)-1
    for x in columnsAr do  (
      lvArg.columns.add x w
      )
    )
 
  on lv mouseClick e do
  (
    if e.button == (dotnetclass "System.Windows.Forms.MouseButtons").right do
    print "RMB Click"
    )
 
  -- This MouseMove event is causing the error
  on lv MouseMove sender e do
  (
    print "Mouse Move"
    )
 
  on lv MouseUp sender e do
  (
   local hit = (lv.HitTest (dotNetObject "System.Drawing.Point" e.x e.y))
   if hit != undefined and e.button == e.button.left do
   _uiKbMouseDown = off
   )
 
  on lv MouseDown sender e do
  (
   local hit=(lv.HitTest (dotNetObject "System.Drawing.Point" e.x e.y))
   if hit != undefined and e.button == e.button.left do
   _uiKbMouseDown = on
   )
 
  on lvRol open do (
    _lvInit lv
    _lvAddColumns lv #("Object", "Class", "Wire Color")
    _lvPopulateList lv
    )
 
  )
createDialog lvRol
jahman's picture

.

it must be something else that causes this error.
I've checked your code in max2014 and it works fine

pixamoon's picture

`

one thing I noticed is there are no sender and event parameters. Did you try with them already?

on lv MouseDown sender e do (print "MouseDown")
3dwannab's picture

.

That's been done too. Have you tried in 2020?

3dwannab's picture

I'm using 2020

Thanks for checking this. Just to confirm that you clicked inside the listview before you pressed escape a few times?

jahman's picture

.

sure, I clicked whereever possible
Just checked it in 2020 now and I confirm that it throws an error on esc
:(

3dwannab's picture

Oh, that's good to know. I

Oh, that's good to know. I was sure I was going mad! :P Thanks.

I'll check to see if this has been fixed with a service pack or send this on to them.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.