Destroying a Wx::GridTableBase with an active editor

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

hi Tony

Sorry been away for a few days…

Tony M. 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

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