# Listbox selected problem

**URL:** <https://forum.xojo.com/t/listbox-selected-problem/52160>\
**Category:** Getting Started\
**Created:** [January 27, 2020, 8:05pm UTC](https://forum.xojo.com/t/listbox-selected-problem/52160 "2020-01-27T20:05:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marco\_Weinrich](https://forum.xojo.com/letter_avatar_proxy/v4/letter/m/6a8cbe/32.png) [@Marco\_Weinrich](https://forum.xojo.com/u/Marco_Weinrich)\
**Post date:** [January 27, 2020, 8:05pm UTC](https://forum.xojo.com/t/listbox-selected-problem/52160/1 "2020-01-27T20:05:16Z")

</div>

Hello,  
i want to fire up the “change” event when a celltag is “active” but the app crashes

the cell background event:

```auto
Dim i as integer
g.ForeColor = app.dunkelblau
g.FillRect(0, 0, g.Width, g.Height)

g.ForeColor=app.hellblau
g.DrawLine(0, me.RowHeight-1, me.width, me.RowHeight-1)

dim s as Integer

if me.listcount>0 then 
  if Me.CellTag(row, 0)="active" then 
    g.ForeColor = app.gruen
    g.FillRect(0, 0, g.Width, g.Height)
    dim p as new Picture(45,30)
    p.Graphics.DrawPicture(playSymbol,15,-2)
    me.RowPicture(row) =p
    me.Selected(row)=true                                 
   return true
  else
    dim p as new Picture(45,30)
    p.Graphics.DrawPicture(playsymbol_inactive,15,-2)
    me.RowPicture(row) =p
  End If
  
end if
```

in the change event

```auto
if me.ListIndex<>-1 then ////app crashes/hangs with this code in "change event" .... why?
  MsgBox str(me.listindex)
end if 
```

anybody can help me with that?

Thanks Marco

---

<div class="post-metadata">

**Author:** ![MarkusR](https://forum.xojo.com/user_avatar/forum.xojo.com/markusr/32/685_2.png) [@MarkusR](https://forum.xojo.com/u/MarkusR)\
**Post date:** [January 27, 2020, 8:59pm UTC](https://forum.xojo.com/t/listbox-selected-problem/52160/2 "2020-01-27T20:59:05Z")

</div>

maybe the select = true cause / call the cell draw event again and again in endless loop.  
try using system.debuglog instead of a msgbox and print a timestamp with the debug output.

---

<div class="post-metadata">

**Author:** ![jim\_mckay](https://forum.xojo.com/user_avatar/forum.xojo.com/jim_mckay/32/905_2.png) [@jim\_mckay](https://forum.xojo.com/u/jim_mckay)\
**Post date:** [January 27, 2020, 10:23pm UTC](https://forum.xojo.com/t/listbox-selected-problem/52160/3 "2020-01-27T22:23:13Z")

</div>

You’re effectively calling msgbox from inside of cellbackgroundpaint.

If you set a breakpoint on the line if me.ListIndex\<\>-1 then you’ll see the change method is being called from the line me.Selected(0)=true

Calling msgBox from a paint event will crash on Mac. It’s not a bug, it’s a feature 😉

Try using [system.debuglog](http://documentation.xojo.com/api/os/system.html#system-debuglog) for this sort of thing.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [April 29, 2021, 4:16pm UTC](https://forum.xojo.com/t/listbox-selected-problem/52160/4 "2021-04-29T16:16:10Z")

</div>


