Forum: wxRuby Add values in GridCellChoiceEditor

Posted by Marija Velickovic (maricanis)
on 2011-04-11 14:32
Hi,

I'm using GridCellChoiceEditor for some cells in Grid object.
At the beginning values inside choice are initialized like in grid.rb
example

@editor_c = Wx::GridCellChoiceEditor.new(['foo', 'bar', 'baz'])
@grid.set_cell_editor(4, 3, @editor_c)

After that when script is started this cell is empty and user can select
one of values. So this behavior is ok.

#
While program is running I want to add new values into this choice
editor, so I do next in the code:
@editor.set_parameters("foo, bar, baz, new")

After that nothing happens and choices still have the same old list of
values.

#
I also tried to use local variable for editor instead on instance
variable:
edit = @grid.get_cell_editor(4,3)
edit.set_parameters("foo, bar, baz,new")
@grid.set_cell_editor(4,3,edit)

Again list is not updated, and 'new' string is not added.

#
Only way I've found for now to be able to update editor, is to have
empty grid (so nothing is selected in choice cells), and then update
editor.
This is no acceptable for my application, because list of values in
choice cells should be updated during the program running few times
(depending on some other user actions).

#
What am I doing wrong?
Is it possible to update list of values in choice editor while program
is running?

Thanks in advance,
Marija
Posted by Marija Velickovic (maricanis)
on 2011-04-12 11:01
Hi again,

I've found possible solution for this problem in WxPython Wiki pages
http://wiki.wxpython.org/GridCellChoiceEditor

from this page:
"A common question is how to dynamically update the list in a 
GridCellChoiceEditor. The problem comes from not having direct access to 
the underlying ComboBox widget in the grid editor. Fortunately the grid 
editor throws an event that allows us to get to the underlying 
ComboBox."

I convert Python code for Ruby but I have a problem how to get 
underlying ComboBox from GridCellChoiceEditor

If I use Wx::GridEditorCreatedEvent.get_control function (like in Python 
code - line 249 on wiki page), I get Wx::Control object instead of 
Wx::ComboBox or Wx::Choice.

So question is how to convert Wx::Control object to Wx::ComboBox to be 
able to dynamically change list of its values.

Hope somebody has an answer,
Marija
Posted by David Beswick (davidbeswick)
on 2011-04-12 12:23
(Received via mailing list)
Hi Marija, that's strange because Ruby doesn't really have a way to cast
between types. Maybe it's a SWIG problem. Could you post a small code 
sample
that shows the issue?
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.