# Problem inserting row in a Grid

**URL:** <https://www.ruby-forum.com/t/problem-inserting-row-in-a-grid/207873>\
**Category:** wxRuby\
**Created:** [June 4, 2011, 9:58pm UTC](https://www.ruby-forum.com/t/problem-inserting-row-in-a-grid/207873 "2011-06-04T21:58:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [June 4, 2011, 9:58pm UTC](https://www.ruby-forum.com/t/problem-inserting-row-in-a-grid/207873/1 "2011-06-04T21:58:12Z")

</div>

I’m having a problem inserting a row in a Grid under Windows. The  
following  
stripped-down program illustrated the problem:

* * *

require ‘rubygems’  
require ‘wx’

include Wx

class TestApp \< App  
def on\_init  
frame = Frame.new(nil, -1, “Application”)  
panel = Panel.new(frame)  
@grid = Grid.new(panel)  
@grid.create\_grid(1, 2)

```
  sizer = BoxSizer.new(VERTICAL)
  sizer.add(@grid, 1, GROW|ALL, 2)
  panel.set_sizer(sizer)

  evt_grid_cell_change do |evt|
     row = evt.get_row
     @grid.insert_rows(row, 1)
  end

  frame.show(TRUE)

```

end  
end

## TestApp.new.main\_loop

The intent is to add a new row when one enters data in the last empty  
row,  
but when data is entered into a cell in the last row, the program  
crashes:

C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in  
`process_event': stack level too deep (SystemStackError) from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in`\_\_insert\_rows’  
from  
C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in  
`insert_rows' from x.rb:19:in`on\_init’  
from  
C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in  
`call' from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in`process\_event’  
from  
C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in  
`__insert_rows' from C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in`insert\_rows’  
from x.rb:19:in `on_init' ... 18546 levels... from x.rb:26:in`process\_event’  
from x.rb:26:in `on_run' from x.rb:26:in`main\_loop’  
from x.rb:26

It looks like insert\_rows is getting invoked recursively. The same  
program  
works fine under FreeBSD, but I think I have an older (pre-wxruby2)  
version  
installed.

---

<div class="post-metadata">

**Author:** ![will\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a87d85/32.png) [@will\_p](https://www.ruby-forum.com/u/will_p)\
**Post date:** [June 5, 2011, 1:37pm UTC](https://www.ruby-forum.com/t/problem-inserting-row-in-a-grid/207873/2 "2011-06-05T13:37:47Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Am 04.06.2011 20:49, schrieb Will P.:

> def on\_init  
> row = evt.get\_row  
> The intent is to add a new row when one enters data in the last empty row,  
> from x.rb:19:in `on_init' ... 18546 levels... from x.rb:26:in `process\_event’  
> from x.rb:26:in `on_run' from x.rb:26:in `main\_loop’  
> from x.rb:26
> 
> It looks like insert\_rows is getting invoked recursively. The same program  
> works fine under FreeBSD, but I think I have an older (pre-wxruby2) version  
> installed.

I’d say that inserting a row causes a EVT\_GRID\_CELL\_CHANGE event,  
effectively calling your event handler again, which in turn issues a new  
EVT\_GRID\_CELL\_CHANGE, causing your event handler to be triggered once  
again, causing… ad infinitum.

You may be able to prevent this by setting an instance variable and  
checking it’s value before trying to insert a row.

Vale,  
Marvin  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.11 (GNU/Linux)  
Comment: Using GnuPG with Mozilla - [http://enigmail.mozdev.org/](http://enigmail.mozdev.org/)

iQEcBAEBAgAGBQJN62hZAAoJELh1XLHFkqhaRo8IAK8MDLwu3kPMJsCVxJ2AMpcN  
yKSu46kGbf2wqvi8EthZhLjeGsjwciYvIUGRK5eZ0hcKrweCAYGroUggGwtxKJWp  
Wd24RwZzR09Q/B1ErFHIPcMgj+0lo6uWOsV7lq2rIMigMMwGbkRc6VVPoUDSyyc0  
rFn3DwU6L5NfyYrSJggodLep6XDUvcaWWvIJW+Afuy3b/awAQkxw5rQbbteB44Nf  
NN/aGcJD7B9ttl6qz0eWeGcPDaBWV1FUSzV+CCGpzsPcL1Kcg1IBTlYXmA2m8WQ8  
jPPZRzNCXzedeK0CifnURK26dZsBwGEpU9Q8B/GFeGMvBt7TB88RHRwuxisfDWI=  
=28vx  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![will\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a87d85/32.png) [@will\_p](https://www.ruby-forum.com/u/will_p)\
**Post date:** [June 6, 2011, 12:10am UTC](https://www.ruby-forum.com/t/problem-inserting-row-in-a-grid/207873/3 "2011-06-06T00:10:58Z")

</div>

On Sun, 05 Jun 2011 13:28:37 +0200, Quintus [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > ```
> > sizer.add(@grid, 1, GROW|ALL, 2)
> > 
> > from 
> > 
> > ```

C:/Ruby/lib/ruby/gems/1.8/gems/wxruby-2.0.1-x86-mswin32-60/lib/wx/classes/grid.rb:105:in  
`call’

> > It looks like insert\_rows is getting invoked recursively. The same program  
> > works fine under FreeBSD, but I think I have an older (pre-wxruby2) version  
> > installed.

Yes, but I’m not sure why it should. IOW this looks to me like a bug in  
wxruby, especially since this didn’t happen on the older wxruby. (I’m  
assuming the operative difference is between wxruby v1 vs. v2 rather  
than  
FreeBSD vs. Windows.)

> I’d say that inserting a row causes a EVT\_GRID\_CELL\_CHANGE event,  
> effectively calling your event handler again, which in turn issues a new  
> EVT\_GRID\_CELL\_CHANGE, causing your event handler to be triggered once  
> again, causing… ad infinitum.
> 
> You may be able to prevent this by setting an instance variable and  
> checking it’s value before trying to insert a row.

Good suggestion - I’ll look into doing that. Gratias ago.

> Vale,  
> Marvin

Et valeas tu.

---

<div class="post-metadata">

**Author:** ![will\_p](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/a87d85/32.png) [@will\_p](https://www.ruby-forum.com/u/will_p)\
**Post date:** [June 6, 2011, 7:25pm UTC](https://www.ruby-forum.com/t/problem-inserting-row-in-a-grid/207873/4 "2011-06-06T19:25:38Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Am 05.06.2011 20:55, schrieb Will P.:

> > > require ‘wx’  
> > > sizer = BoxSizer.new(VERTICAL)  
> > > end  
> > > from x.rb:19:in `on\_init’
> > > 
> > > It looks like insert\_rows is getting invoked recursively. The same program  
> > > works fine under FreeBSD, but I think I have an older (pre-wxruby2) version  
> > > installed.
> 
> Yes, but I’m not sure why it should. IOW this looks to me like a bug in  
> wxruby, especially since this didn’t happen on the older wxruby. (I’m  
> assuming the operative difference is between wxruby v1 vs. v2 rather than  
> FreeBSD vs. Windows.)

wxRuby (or at least wxWidgets) sometimes behaves a little different on  
Windows, especially regarding events. The most recent case I experienced  
was a TreeCtrl getting an EVT\_SELECTION\_CHANGED event during application  
startup, which it doesn’t get on Linux. Both systems used wxRuby 2.0.1.

> > I’d say that inserting a row causes a EVT\_GRID\_CELL\_CHANGE event,  
> > effectively calling your event handler again, which in turn issues a new  
> > EVT\_GRID\_CELL\_CHANGE, causing your event handler to be triggered once  
> > again, causing… ad infinitum.
> > 
> > You may be able to prevent this by setting an instance variable and  
> > checking it’s value before trying to insert a row.
> 
> Good suggestion - I’ll look into doing that. Gratias ago.

Adiuvare mihi gaudium est. 😉

> > Vale,  
> > Marvin
> 
> Et valeas tu.

Si vales, bene est, ego quidem valeo. (I think it was the younger Pliny  
always shortening this to SVBEEQV).

But the times I was used to Latin are gone now, hopefully the few  
phrases above are gramicatically correct 😉  
Nevertheless I like Latin for being able to understand some phrases in  
Spanish, Italian or even English I’ve never encountered before (I’m from  
Germany). And, of course, being able to read (at least with a bit of  
efford of reactivating old knowledge) these _really_ old texts is just  
cool.

Vale,  
Marvin alias Quintus  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.11 (GNU/Linux)  
Comment: Using GnuPG with Mozilla - [http://enigmail.mozdev.org/](http://enigmail.mozdev.org/)

iQEcBAEBAgAGBQJN7P5BAAoJELh1XLHFkqhaUk0H/0DOfWGx/VaE56X2UJFt3ylH  
hw5/apXeWxKnTal80L2+bqF9/yNg14qjYZCJEBJ6nJ54Eh/DggTKN1jAkg5Fz+5Y  
lM5/O3VQKYUgs14hLMEZSRykIL5p4tZAxXbC4MOxrwNE1FhiUrGlIZ3esBH4MoL4  
xE/jg4ydXuWiOUw+KNjPd7NOMAGQ9zDWy2kA7Ku2hjUyM4ttnACYyQki2DFISm97  
1yhz4pCYzO0JyJiJ1pslXtbop2XACW/nyqqddgt0HlMhdfzpqOffnyUnjH5rducg  
2XXjLXuFsyNJ9JMgsEm98/p0Vrs+lqlLSEsvDZnaQSKeDjJCSJT86rogdMiXI5Y=  
=1kQB  
-----END PGP SIGNATURE-----
