Forum: wxRuby Moving text on a window

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jason S. (Guest)
on 2008-12-16 18:09
(Received via mailing list)
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
Alex F. (Guest)
on 2008-12-16 18:18
(Received via mailing list)
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
Jason S. (Guest)
on 2008-12-16 21:02
(Received via mailing list)
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
Alex F. (Guest)
on 2008-12-16 21:53
(Received via mailing list)
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
This topic is locked and can not be replied to.