# Preserve selections

**URL:** <https://www.ruby-forum.com/t/preserve-selections/188767>\
**Category:** wxRuby\
**Created:** [May 18, 2010, 9:07am UTC](https://www.ruby-forum.com/t/preserve-selections/188767 "2010-05-18T09:07:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mszatanik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@mszatanik](https://www.ruby-forum.com/u/mszatanik)\
**Post date:** [May 18, 2010, 9:07am UTC](https://www.ruby-forum.com/t/preserve-selections/188767/1 "2010-05-18T09:07:36Z")

</div>

hi,

could any1 help me to figure out how to preserve selections in extended  
listbox please?

f.e. i have a button to move up/down selected item(s), but after i click  
it and selection goes up or down i loose selections.

i’d like to create an array which would hold those selections via  
get\_selections(), but i dont see any method to select an item in a  
listbox.

Best regards  
M.Szatanik

---

<div class="post-metadata">

**Author:** ![mszatanik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@mszatanik](https://www.ruby-forum.com/u/mszatanik)\
**Post date:** [May 18, 2010, 10:22am UTC](https://www.ruby-forum.com/t/preserve-selections/188767/2 "2010-05-18T10:22:36Z")

</div>

If you really needs selection,  
perhaps you can use checklistbox ?

---

<div class="post-metadata">

**Author:** ![mszatanik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@mszatanik](https://www.ruby-forum.com/u/mszatanik)\
**Post date:** [May 18, 2010, 11:12am UTC](https://www.ruby-forum.com/t/preserve-selections/188767/3 "2010-05-18T11:12:08Z")

</div>

will thought it over, at least its a solution 🙂 thx a lot.

---

<div class="post-metadata">

**Author:** ![mszatanik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@mszatanik](https://www.ruby-forum.com/u/mszatanik)\
**Post date:** [May 18, 2010, 2:22pm UTC](https://www.ruby-forum.com/t/preserve-selections/188767/4 "2010-05-18T14:22:16Z")

</div>

Alex F. wrote:

> On 18/05/2010 08:07, Maciej S. wrote:
> 
> > could any1 help me to figure out how to preserve selections in extended  
> > listbox please?
> > 
> > f.e. i have a button to move up/down selected item(s), but after i click  
> > it and selection goes up or down i loose selections.
> > 
> > i’d like to create an array which would hold those selections via  
> > get\_selections(), but i dont see any method to select an item in a  
> > listbox.
> 
> The method you want is select() - ListBox inherits it from  
> Wx::ControlWithItems.
> 
> alex

thx a lot :\* will check it out right away.  
from now on i will always check those damn parents 😛

---

<div class="post-metadata">

**Author:** ![mszatanik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@mszatanik](https://www.ruby-forum.com/u/mszatanik)\
**Post date:** [May 18, 2010, 2:19pm UTC](https://www.ruby-forum.com/t/preserve-selections/188767/5 "2010-05-18T14:19:06Z")

</div>

On 18/05/2010 08:07, Maciej S. wrote:

> could any1 help me to figure out how to preserve selections in extended  
> listbox please?
> 
> f.e. i have a button to move up/down selected item(s), but after i click  
> it and selection goes up or down i loose selections.
> 
> i’d like to create an array which would hold those selections via  
> get\_selections(), but i dont see any method to select an item in a  
> listbox.

The method you want is select() - ListBox inherits it from  
Wx::ControlWithItems.

alex

---

<div class="post-metadata">

**Author:** ![mszatanik](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/bcef8e/32.png) [@mszatanik](https://www.ruby-forum.com/u/mszatanik)\
**Post date:** [May 18, 2010, 3:25pm UTC](https://www.ruby-forum.com/t/preserve-selections/188767/6 "2010-05-18T15:25:46Z")

</div>

Maciej S. wrote:

> Alex F. wrote:
> 
> > On 18/05/2010 08:07, Maciej S. wrote:
> > 
> > > could any1 help me to figure out how to preserve selections in extended  
> > > listbox please?
> > > 
> > > f.e. i have a button to move up/down selected item(s), but after i click  
> > > it and selection goes up or down i loose selections.
> > > 
> > > i’d like to create an array which would hold those selections via  
> > > get\_selections(), but i dont see any method to select an item in a  
> > > listbox.
> > 
> > The method you want is select() - ListBox inherits it from  
> > Wx::ControlWithItems.
> > 
> > alex
> 
> thx a lot :\* will check it out right away.  
> from now on i will always check those damn parents 😛

yup, it works, thanks again.  
An example if any1 is interested.

```
      Array.each do |cell|
        @listbox.select(cell)
      end

```
