# ListCtrl.get\_selections broken?

**URL:** <https://www.ruby-forum.com/t/listctrl-get-selections-broken/167805>\
**Category:** wxRuby\
**Created:** [May 12, 2009, 7:35pm UTC](https://www.ruby-forum.com/t/listctrl-get-selections-broken/167805 "2009-05-12T19:35:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phil\_Puccio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5fc32e/32.png) [@Phil\_Puccio](https://www.ruby-forum.com/u/Phil_Puccio)\
**Post date:** [May 12, 2009, 7:35pm UTC](https://www.ruby-forum.com/t/listctrl-get-selections-broken/167805/1 "2009-05-12T19:35:43Z")

</div>

Hi,

In a thread back in March, Alex F. provided a fix in one line of  
ListCtrl.get\_selections:

> end  
> The only change is Wx::LIST\_NEXT\_ALL was previously LIST\_NEXT\_BELOW.

That fix got me past my initial problem, too, but then I found that if  
I sent get\_selections to a ListCtrl with only one row or with no rows  
(I’m using report mode), the code would go into a loop and hang my  
CPU. After changing the second reference of Wx::LIST\_NEXT\_BELOW to  
Wx::LIST\_NEXT\_ALL, everything worked fine for me.

Alex, you might want to consider this additional change.

Thanks,

Phil

---

<div class="post-metadata">

**Author:** ![Phil\_Puccio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5fc32e/32.png) [@Phil\_Puccio](https://www.ruby-forum.com/u/Phil_Puccio)\
**Post date:** [May 13, 2009, 4:13am UTC](https://www.ruby-forum.com/t/listctrl-get-selections-broken/167805/2 "2009-05-13T04:13:45Z")

</div>

Sorry, my original posting omitted most of the method I was referring  
to. The fixed method as originally posted by Alex was:

class Wx::ListCtrl  
def get\_selections  
selections = []  
item = get\_next\_item(-1, Wx::LIST\_NEXT\_ALL, Wx::LIST\_STATE\_SELECTED)  
while item \>= 0  
selections \<\< item  
item = get\_next\_item(item, Wx::LIST\_NEXT\_BELOW,  
Wx::LIST\_STATE\_SELECTED)  
end  
selections  
end  
end

My suggestion is that the second Wx::LIST\_NEXT\_BELOW be changed to  
Wx::LIST\_NEXT\_ALL .

Phil

---

<div class="post-metadata">

**Author:** ![Phil\_Puccio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/5fc32e/32.png) [@Phil\_Puccio](https://www.ruby-forum.com/u/Phil_Puccio)\
**Post date:** [May 14, 2009, 3:27pm UTC](https://www.ruby-forum.com/t/listctrl-get-selections-broken/167805/3 "2009-05-14T15:27:32Z")

</div>

Phil Puccio wrote:

> > ```
> > selections << item
> > item = get_next_item(item, Wx::LIST_NEXT_BELOW, Wx::LIST_STATE_SELECTED)
> > 
> > ```
> > 
> > end  
> > selections  
> > end  
> > end  
> > The only change is Wx::LIST\_NEXT\_ALL was previously LIST\_NEXT\_BELOW.  
> > That fix got me past my initial problem, too, but then I found that if I sent get\_selections to a ListCtrl with only one row or with no rows (I’m using report mode), the code would go into a loop and hang my CPU. After changing the second reference of Wx::LIST\_NEXT\_BELOW to Wx::LIST\_NEXT\_ALL, everything worked fine for me.  
> > Alex, you might want to consider this additional change.

Thanks very much Phil, I’ve committed this change to SVN

alex
