ScriptSpot

Forum topic · General Scripting

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

By 3dwannab · 2019-08-22

Description

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 (7)

Narrowed down the problem

3dwannab · 2019-09-22

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 · 2019-08-22

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

I'm using 2020

3dwannab · 2019-08-23

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

.

jahman · 2019-08-23

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

3dwannab · 2019-08-23

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.

`

pixamoon · 2019-08-27

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 · 2019-08-27

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