# How to implement a grid view?

**URL:** <https://www.ruby-forum.com/t/how-to-implement-a-grid-view/132227>\
**Category:** Ruby-Gnome 2\
**Created:** [March 18, 2008, 2:44am UTC](https://www.ruby-forum.com/t/how-to-implement-a-grid-view/132227 "2008-03-18T02:44:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shinwoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@shinwoo](https://www.ruby-forum.com/u/shinwoo)\
**Post date:** [March 18, 2008, 2:44am UTC](https://www.ruby-forum.com/t/how-to-implement-a-grid-view/132227/1 "2008-03-18T02:44:48Z")

</div>

Hi,

I would like to have a grid view like excel which I can use the  
cell(col,row) to access and change the value(text and bgcolor). Anyone  
has some sample for me? I know the treeview can solve this problem but  
it is too complex for me and I just want a simple grid view like excel.

For now, I only can think to write a model class for the treeview that  
can be access using the row, column. But how do I initialize the col,  
row model is still fuzzy for me. I am still new to gtk also.

Or may be a model like this:  
col, row, text, bgcolor #model header  
0, 0, ‘text’, ‘blue’  
0, 1, ‘another’, ‘yellow’  
1, 0, ‘blah’, ‘blue’  
1, 1, ‘hello’, ‘red’

In this case, how do I access it specific cell using the cell(row,  
column)? Need to iterate all the row until it match the col, row? seems  
uneffective for me.

thanks in advance

Regards,  
Shin Guey

---

<div class="post-metadata">

**Author:** ![shinwoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@shinwoo](https://www.ruby-forum.com/u/shinwoo)\
**Post date:** [March 18, 2008, 11:47am UTC](https://www.ruby-forum.com/t/how-to-implement-a-grid-view/132227/2 "2008-03-18T11:47:56Z")

</div>

I am not sure whether this specifically is possible.  
Maybe have a look at Gnumeric to get a hint on how this could be done in  
ruby-gtk (if you are not afraid to dig into C).

Personally I think using a Table might be the best compromise (it  
probably does not suffice your use case though)

---

<div class="post-metadata">

**Author:** ![shinwoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@shinwoo](https://www.ruby-forum.com/u/shinwoo)\
**Post date:** [March 18, 2008, 2:18pm UTC](https://www.ruby-forum.com/t/how-to-implement-a-grid-view/132227/3 "2008-03-18T14:18:21Z")

</div>

Marc H. wrote:

> I am not sure whether this specifically is possible.  
> Maybe have a look at Gnumeric to get a hint on how this could be done in  
> ruby-gtk (if you are not afraid to dig into C).

I just take a look at Gnumeric. It is great but overkill for my need. I  
wonder how they implement it using TreeView or they are not using  
TreeView but customize widget? I will take a look later.

> Personally I think using a Table might be the best compromise (it  
> probably does not suffice your use case though)

Yes, I was thinking to use Table but in some case I need a grid with  
14000+ row, then I am sure using Table is not suitable.

thanks for the reply. Hopefully someone can help me on this.

---

<div class="post-metadata">

**Author:** ![shinwoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@shinwoo](https://www.ruby-forum.com/u/shinwoo)\
**Post date:** [March 18, 2008, 8:21pm UTC](https://www.ruby-forum.com/t/how-to-implement-a-grid-view/132227/4 "2008-03-18T20:21:44Z")

</div>

Am Dienstag, den 18.03.2008, 02:44 +0100 schrieb Shin guey Wong:

> 

Hi,

If you want to use the TreeView, your model should be a Gtk::ListStore.

A single cell you can access with Gtk::TreeIter.get\_value and  
Gtk::TreeIter.set\_value.

If it’s possible to set the background to each cell indipendently i  
don’t know.

To learn more about the TreeView read this:  
[http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-treeview](http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-treeview)

An other option is to use Gtk::Sheet from GtkExtra ([gtkextra.sf.net](http://gtkextra.sf.net)).  
That is a real sheet like the one in a spreatsheet. The down sides are,  
that you have to create ruby bindings on your own (that is fun 🙂 ) and  
that the project seem to be near dead.

Cheers, detlef

---

<div class="post-metadata">

**Author:** ![shinwoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@shinwoo](https://www.ruby-forum.com/u/shinwoo)\
**Post date:** [March 19, 2008, 2:16am UTC](https://www.ruby-forum.com/t/how-to-implement-a-grid-view/132227/5 "2008-03-19T02:16:04Z")

</div>

Detlef R. wrote:

> An other option is to use Gtk::Sheet from GtkExtra ([gtkextra.sf.net](http://gtkextra.sf.net)).  
> That is a real sheet like the one in a spreatsheet. The down sides are,  
> that you have to create ruby bindings on your own (that is fun 🙂 ) and  
> that the project seem to be near dead.
> 
> Cheers, detlef

thanks.  
Hmm, I never create any GTK widget binding for ruby before. I only  
created a c-extension for ruby before. I will take a look and see  
whether I can do it or not and how much time to take. BTW, I am working  
on windows platform and I am not sure the Gtk::Sheet will be working on  
windows or not. ☹

---

<div class="post-metadata">

**Author:** ![shinwoo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/df705f/32.png) [@shinwoo](https://www.ruby-forum.com/u/shinwoo)\
**Post date:** [March 19, 2008, 3:10pm UTC](https://www.ruby-forum.com/t/how-to-implement-a-grid-view/132227/6 "2008-03-19T15:10:02Z")

</div>

Shin guey Wong wrote:

> BTW, I am working  
> on windows platform and I am not sure the Gtk::Sheet will be working on  
> windows or not. ☹

There is a win32 port for the extra libraries:

> **[win32 ports of GTK, Glade, Libglade, gtkextra, GWF etc.](https://wingtk.sourceforge.net/)**
>
> Visual automatic code generator and complete Windows programming environment
