Forum: wxRuby Problem inserting row into a grid

Posted by Norbert Lange (lange_n)
on 2013-01-02 19:31
Attachment: SpreadsheetCodeSample.txt (1,9 KB)
I'm having a bit of a problem inserting a row (or column) into a grid.
I'm using my own custom GridTableBase and created override methods for
insert_rows, insert_cols, get_number_rows and get_number_cols.  The
problem I'm having is that calling the grid.insert_rows method does not
properly update the number of rows displayed, and the last row of the
table disappears into oblivion even though it still exists in the
underlying GridTableBase.

The attached code is a simplified version of my code that should
illustrate the problem I'm having.

Thanks,
Norbert
Posted by Alex Fenton (Guest)
on 2013-01-03 03:07
(Received via mailing list)
Hi Norbert

On 02/01/13 18:31, Norbert Lange wrote:
> I'm having a bit of a problem inserting a row (or column) into a grid.
> I'm using my own custom GridTableBase and created override methods for
> insert_rows, insert_cols, get_number_rows and get_number_cols.  The
> problem I'm having is that calling the grid.insert_rows method does not
> properly update the number of rows displayed, and the last row of the
> table disappears into oblivion even though it still exists in the
> underlying GridTableBase

I think I ran into a similar problem a while ago. I solved it by
re-calling the set_table method, which causes the Grid to inspect the
DataSource again to determine the number of rows and columns.

See the sub-classed refresh method in
http://weft-qda.rubyforge.org/svn/trunk/weft-qda/l...

best
alex
Posted by Norbert Lange (lange_n)
on 2013-01-03 17:51
Hi Alex,

I gave your suggestion a try but it results in a segmentation fault when 
I try to set the table for a second time, even if I do it immediately 
after the first grid.set_table before any manipulation of the table.

C:/Ruby187/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mingw32/lib/wx/classes/grid.rb:34: 
[BUG] Segmentation fault
ruby 1.8.7 (2011-12-28 patchlevel 357) [i386-mingw32]

Any other thoughts would be appreciated.

Regards,
Norbert
Posted by Norbert Lange (lange_n)
on 2013-01-05 00:26
After another bit of experimenting, I've found that if I create a new 
grid and then use the grid.create_grid method() to create a table that 
inserting rows into that table works.  What I'm concluding is that I've 
implemented something incorrectly in my SpreadsheetTable class or 
perhaps missed implementing a virtual function properly.

Again, any suggestions anyone may have would be appreciated.

Regards,
Norbert
Posted by Alex Fenton (Guest)
on 2013-01-05 18:13
(Received via mailing list)
On 05/01/2013 00:26, Norbert Lange wrote:
> After another bit of experimenting, I've found that if I create a new
> grid and then use the grid.create_grid method() to create a table that
> inserting rows into that table works.  What I'm concluding is that I've
> implemented something incorrectly in my SpreadsheetTable class or
> perhaps missed implementing a virtual function properly.
I don't think so; see this on the C++ version:
http://stackoverflow.com/questions/8857610/refresh...

Does calling force_refresh() help? It appears to be available in wxRuby.

alex
Posted by Norbert Lange (lange_n)
on 2013-01-07 17:14
Hi Alex,

Calling force_refresh doesn't seem to help.  The problem seems to be 
centered around the grid not properly updating after the underlying 
table is changed.  The following code snippet illustrates I think that 
the grid is not calling the gtb get_number_rows method except perhaps 
during the initial grid.set_table call.

gtb = SpreadsheetTable.new(["A","B"], ["10","20"], [[1,2],[3,4]])
grid = Wx::Grid.new(panel, -1)
grid.set_table(gtb)
grid.insert_rows(1,1)
grid.force_refresh

# Grid thinks there are still just 2 rows
puts grid.get_number_rows

# Correctly indicates 3 rows
puts gtb.get_number_rows

Regards,
Norbert
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.