# Moving text on a window

**URL:** <https://www.ruby-forum.com/t/moving-text-on-a-window/155774>\
**Category:** wxRuby\
**Created:** [December 16, 2008, 5:09pm UTC](https://www.ruby-forum.com/t/moving-text-on-a-window/155774 "2008-12-16T17:09:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [December 16, 2008, 5:09pm UTC](https://www.ruby-forum.com/t/moving-text-on-a-window/155774/1 "2008-12-16T17:09:13Z")

</div>

All,

I am new to WxRuby, and I am reading the online WxRuby Documentation for  
help. I want to add a control to my application that can move text  
between two text controls on a window. For example, let’s say that I  
have a text/list control with 3 text strings in it, ‘one’, ‘two’, and  
‘three’. I want to be able to highlight ‘one’, click a button, and have  
‘one’ appear in another text/list control on the window, and the  
original window should only have ‘two’ and ‘three’ displayed in it now.  
I can elaborate if this is not clear. Thank you in advance for any  
help.

- Shelton

---

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [December 16, 2008, 5:18pm UTC](https://www.ruby-forum.com/t/moving-text-on-a-window/155774/2 "2008-12-16T17:18:01Z")

</div>

Jason S. wrote:

> I am new to WxRuby, and I am reading the online WxRuby Documentation  
> for help. I want to add a control to my application that can move  
> text between two text controls on a window. For example, let’s say  
> that I have a text/list control with 3 text strings in it, ‘one’,  
> ‘two’, and ‘three’. I want to be able to highlight ‘one’, click a  
> button, and have ‘one’ appear in another text/list control on the  
> window, and the original window should only have ‘two’ and ‘three’  
> displayed in it now. I can elaborate if this is not clear. Thank you  
> in advance for any help.

Exactly how to do this depends on the type of control you’re copying  
from and to. Assuming you’re using Wx::ListBox, which is nice and  
simple, something like (untested):

# assuming the\_button is the Wx::Button

evt\_button(the\_button) do

# get the selected text from the original window

sel\_text = list\_1.string\_selection

# add it to the other window

list\_2.append (sel\_text)

# delete the selection in the old window

list\_1.delete( list\_1.selection )  
end

a

---

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [December 16, 2008, 8:02pm UTC](https://www.ruby-forum.com/t/moving-text-on-a-window/155774/3 "2008-12-16T20:02:19Z")

</div>

Thank you for your response, it was very helpful. I have another  
question concerning this issue. Once I have appended the selections  
from ‘list1’ to ‘list2’, is there some sort of ‘getValue’ method that  
will return the contents of the ‘list2’ list box, maybe into an array?  
I have used the ‘getValue’ method to get the value of a combo box, but  
what is the method for a list box. Thanks in advance for any help.

- Shelton\> Date: Tue, 16 Dec 2008 16:15:51 +0000\> From:  
removed\_email\_address@domain.invalid\> To: removed\_email\_address@domain.invalid\> Subject: Re:  
[wxruby-users] Moving text on a window\> \> Jason S. wrote:\> \> I am  
new to WxRuby, and I am reading the online WxRuby Documentation \> \> for  
help. I want to add a control to my application that can move \> \> text  
between two text controls on a window. For example, let’s say \> \> that I  
have a text/list control with 3 text strings in it, ‘one’, \> \> ‘two’,  
and ‘three’. I want to be able to highlight ‘one’, click a \> \> button,  
and have ‘one’ appear in another text/list control on the \> \> window,  
and the original window should only have ‘two’ and ‘three’ \> \> displayed  
in it now. I can elaborate if this is not clear. Thank you \> \> in  
advance for any help.\> \> Exactly how to do this depends on the type of  
control you’re copying \> from and to. Assuming you’re using Wx::ListBox,  
which is nice and \> simple, something like (untested):\> \> # assuming  
the\_button is the Wx::Button\> evt\_button(the\_button) do\> # get the  
selected text from the original window\> sel\_text =  
list\_1.string\_selection\> # add it to the other window\> list\_2.append  
(sel\_text)\> # delete the selection in the old window\> list\_1.delete(  
list\_1.selection )\> end\> \> \> a\>  
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\> wxruby-users mailing  
list\> removed\_email\_address@domain.invalid\>  
[http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)

---

<div class="post-metadata">

**Author:** ![sweatje](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ad7895/32.png) [@sweatje](https://www.ruby-forum.com/u/sweatje)\
**Post date:** [December 16, 2008, 8:53pm UTC](https://www.ruby-forum.com/t/moving-text-on-a-window/155774/4 "2008-12-16T20:53:24Z")

</div>

Jason S. wrote:

> Thank you for your response, it was very helpful. I have another  
> question concerning this issue. Once I have appended the selections  
> from ‘list1’ to ‘list2’, is there some sort of ‘getValue’ method that  
> will return the contents of the ‘list2’ list box, maybe into an array?  
> If you want every text item in the listbox:

listbox.map { | i | listbox.string(i) }

If you want the text for selected items only:

listbox.selections.map { | i | listbox.string(i) }

a
