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 Attachments: http://www.ruby-forum.com/attachment/8000/SpreadsheetCodeSample.txt -- Posted via http://www.ruby-forum.com/.
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 GridTableBaseI 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/lib/weft/wxgui/controls/codereview_grid.rb best alex
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 via http://www.ruby-forum.com/.
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 via http://www.ruby-forum.com/.
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/refreshing-wxgrid-with-dynamic-contents Does calling force_refresh() help? It appears to be available in wxRuby. alex
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 -- Posted via http://www.ruby-forum.com/.