Forum: wxRuby Destroying a Wx::GridTableBase with an active editor

Posted by Chloro Form (tony44)
on 2010-05-06 19:11
Hi!

I'm getting a strange effect when I exchange the table base while an
editor is active. The edit control would stay active and it would be
impossible to remove it from the GUI.

Here's how my app works:

There is a tree structure that allows selection of a group of parameters
to display in the grid. When the user clicks an entry in the tree, I run
the following code snippet:

  def on_tree_selection_changed event
    @grid.begin_batch

    table = @grid.get_table
    table.detach if (table and table.respond_to? "detach") # custom
method to disconnect the table from the data source
    table = MyGridTableBase.new @params
    @grid.set_table table
    @grid.end_batch
    event.skip
  end

This works fine in most cases.

The strange part happens when the opens a cell editor and, while the
editor is open, changes the tree selection.

In that case, the grid would change its table base but the open cell
editor would remain open until the program quits.

My question is, how can I 'automatically' close any open editors on a
grid if the user decides to change the underlying table?

Thanks in advance,
Tony
Posted by Alex Fenton (Guest)
on 2010-05-11 16:39
(Received via mailing list)
hi Tony

Sorry been away for a few days...

Tony Meier wrote:
> The strange part happens when the opens a cell editor and, while the
> editor is open, changes the tree selection.
>
> In that case, the grid would change its table base but the open cell
> editor would remain open until the program quits.
>
> My question is, how can I 'automatically' close any open editors on a
> grid if the user decides to change the underlying table?

The base class Wx::GridCellEditor has a method #end_edit which IIRC
dismisses the current editor - does this help? You may need to track
where there is a current editor with the various event hooks in Wx::GRid
- eg evt_grid_editor_shown / evt_grid_editor_created

a
Posted by Chloro Form (tony44)
on 2010-06-10 18:28
Hey Alex,

just to let you know how things turned out. Briefly speaking, disabling 
editing and the cell_edit_controls does the trick.

Here's the long version:

> The base class Wx::GridCellEditor has a method #end_edit which IIRC
> dismisses the current editor - does this help? You may need to track
> where there is a current editor with the various event hooks in Wx::GRid
> - eg evt_grid_editor_shown / evt_grid_editor_created

I tried that but it seems that the editor isn't affected by that. What I 
did is, I was tracking the active editor in @arow & @acol using the 
grid_editor_shown/hidden events. That worked fine.

However ..

editor = @grid.get_cell_editor (@arow,@acol)
editor.end_edit (@arow,@acol,@grid)

.. didn't seem to anything. I'm still puzzled on how this all works 
together under the hood.

Eventually, I was able to resolve the problem (exchanging table with an 
active editor) by using the following

  def on_tree_selection_changed event
    @grid.begin_batch
    @grid.clear_selection
    @grid.enable_editing(false)
    @grid.enable_cell_edit_control(false)
    table = @grid.get_table
    table.detach if (table and table.respond_to? "detach")
    table = MyGridTableBase.new @params
    @grid.set_table table
    @grid.enable_cell_edit_control(true)
    @grid.enable_editing(true)
    @grid.end_batch
    event.skip
  end

Cheers,
Tony
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.