# How to make a Grid reread the number of rows in a Table?

**URL:** <https://www.ruby-forum.com/t/how-to-make-a-grid-reread-the-number-of-rows-in-a-table/179863>\
**Category:** wxRuby\
**Created:** [December 5, 2009, 8:00pm UTC](https://www.ruby-forum.com/t/how-to-make-a-grid-reread-the-number-of-rows-in-a-table/179863 "2009-12-05T20:00:52Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/u/Svend_Haugaard_SSSS)\
**Post date:** [December 5, 2009, 8:00pm UTC](https://www.ruby-forum.com/t/how-to-make-a-grid-reread-the-number-of-rows-in-a-table/179863/1 "2009-12-05T20:00:52Z")

</div>

I have used GridTableBase to make and display a Table using a Grid.

But if I add a new row to the Table the Grid will not display a new row.

So if I start with 9 rows in the table and add a row, so there is  
10 rows in the table. But the Grid will only display 9 rows.

Is seems like the Grid don’t reread the the numbers of rows from  
the Table.

How can I force the Grid to reread the number of rows?

---

<div class="post-metadata">

**Author:** ![Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/u/Svend_Haugaard_SSSS)\
**Post date:** [December 6, 2009, 6:14am UTC](https://www.ruby-forum.com/t/how-to-make-a-grid-reread-the-number-of-rows-in-a-table/179863/2 "2009-12-06T06:14:46Z")

</div>

Svend Haugaard Sørensen wrote:

> How can I force the Grid to reread the number of rows?  
> grid.refresh(), I think

alex

---

<div class="post-metadata">

**Author:** ![Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/u/Svend_Haugaard_SSSS)\
**Post date:** [December 6, 2009, 4:52pm UTC](https://www.ruby-forum.com/t/how-to-make-a-grid-reread-the-number-of-rows-in-a-table/179863/3 "2009-12-06T16:52:41Z")

</div>

On Sun, 06 Dec 2009 05:14:06 +0000  
Alex F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > the Table.
> > 
> > How can I force the Grid to reread the number of rows?
> 
> grid.refresh(), I think

grid.refresh and grid.force\_refresh only update the data in the cells  
but not the number of rows.

---

<div class="post-metadata">

**Author:** ![Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/u/Svend_Haugaard_SSSS)\
**Post date:** [December 11, 2009, 10:11pm UTC](https://www.ruby-forum.com/t/how-to-make-a-grid-reread-the-number-of-rows-in-a-table/179863/4 "2009-12-11T22:11:12Z")

</div>

On Sun, 6 Dec 2009 16:50:12 +0100  
Svend Haugaard SÃ¸rensen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Sun, 06 Dec 2009 05:14:06 +0000  
> Alex F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Svend Haugaard SÃ¸rensen wrote:
> > 
> > > I have used GridTableBase to make and display a Table using a  
> > > Grid.
> > > 
> > > But if I add a new row to the Table the Grid will not display a  
> > > new row.

Okay I solved it by dropping the table and making a subclass of Grid.  
And then using ‘append\_rows’ and ‘delete\_rows’ from the Grid class.

It seems like ‘set\_table’ in Grid makes a clone of the table, and  
thereby make it impossible to manipulate the table directly.

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/u/Svend_Haugaard_SSSS)\
**Post date:** [February 24, 2010, 8:32pm UTC](https://www.ruby-forum.com/t/how-to-make-a-grid-reread-the-number-of-rows-in-a-table/179863/5 "2010-02-24T20:32:16Z")

</div>

Tony M. wrote:

> Can anyone confirm this is the way to go?

Answering my own question - yes, that seems to do the trick. When the  
underlying data changes, simply create a new table (a subclass of  
GridTableBase to be exact) and call mygrid.set\_table again. Voila.

---

<div class="post-metadata">

**Author:** ![Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/u/Svend_Haugaard_SSSS)\
**Post date:** [February 24, 2010, 9:38pm UTC](https://www.ruby-forum.com/t/how-to-make-a-grid-reread-the-number-of-rows-in-a-table/179863/6 "2010-02-24T21:38:16Z")

</div>

On 23/02/2010 15:27, Tony M. wrote:

> > It seems like ‘set\_table’ in Grid makes a clone of the table, and  
> > thereby make it impossible to manipulate the table directly.
> 
> Can anyone confirm this is the way to go?

Yes, definitely. I looked at wxWidgets underlying C++ code for this a  
while back. It clones the C++ object, so it’s likely the Ruby Grid class  
will continue to have this behaviour.

a

---

<div class="post-metadata">

**Author:** ![Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/u/Svend_Haugaard_SSSS)\
**Post date:** [February 23, 2010, 4:27pm UTC](https://www.ruby-forum.com/t/how-to-make-a-grid-reread-the-number-of-rows-in-a-table/179863/7 "2010-02-23T16:27:44Z")

</div>

> Okay I solved it by dropping the table and making a subclass of Grid.  
> And then using ‘append\_rows’ and ‘delete\_rows’ from the Grid class.
> 
> It seems like ‘set\_table’ in Grid makes a clone of the table, and  
> thereby make it impossible to manipulate the table directly.

Can anyone confirm this is the way to go?

---

<div class="post-metadata">

**Author:** ![Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c68b51/32.png) [@Svend\_Haugaard\_SSSS](https://www.ruby-forum.com/u/Svend_Haugaard_SSSS)\
**Post date:** [February 24, 2010, 9:44pm UTC](https://www.ruby-forum.com/t/how-to-make-a-grid-reread-the-number-of-rows-in-a-table/179863/8 "2010-02-24T21:44:43Z")

</div>

On 23/02/2010 15:27, Tony M. wrote:

> > It seems like ‘set\_table’ in Grid makes a clone of the table, and  
> > thereby make it impossible to manipulate the table directly.
> 
> Can anyone confirm this is the way to go?

Yes, definitely. I looked at wxWidgets underlying C++ code for this a  
while back. It clones the C++ object, so it’s likely the Ruby Grid class  
will continue to have this behaviour.

a
