# Editable cells, does each column need its own renderer?

**URL:** <https://www.ruby-forum.com/t/editable-cells-does-each-column-need-its-own-renderer/108882>\
**Category:** Ruby-Gnome 2\
**Created:** [July 8, 2007, 9:25pm UTC](https://www.ruby-forum.com/t/editable-cells-does-each-column-need-its-own-renderer/108882 "2007-07-08T21:25:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@alex](https://www.ruby-forum.com/u/alex)\
**Post date:** [July 8, 2007, 9:25pm UTC](https://www.ruby-forum.com/t/editable-cells-does-each-column-need-its-own-renderer/108882/1 "2007-07-08T21:25:52Z")

</div>

In the example that comes with ruby-gtk:  
editable\_cells.rb

each column gets its own renderer and each renderer is given a column  
number so that when the renderer gets the ‘edited’ signal, it already  
knows which data is being edited because it can get the iterator [row]  
and it already knows the column number.

So I’m wondering, is there any way to re-use renderers for many  
columns yet still allow the data to be editable? If so, how can I get  
the column number for the cell that is being edited in an ‘edited’  
signal handler?

btw, the docs say: “Typically, one cell renderer is used to draw many  
cells on the screen. To this extent, it isn’t expected that a  
CellRenderer keep any permanent state around.”

-Alex

* * *

This [SF.net](http://SF.net) email is sponsored by DB2 Express  
Download DB2 Express C - the FREE version of DB2 express and take  
control of your XML. No limits. Just data. Click to get it now.  
[http://sourceforge.net/powerbar/db2/](http://sourceforge.net/powerbar/db2/)

---

<div class="post-metadata">

**Author:** ![alex](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/db5fbb/32.png) [@alex](https://www.ruby-forum.com/u/alex)\
**Post date:** [July 11, 2007, 11:46pm UTC](https://www.ruby-forum.com/t/editable-cells-does-each-column-need-its-own-renderer/108882/2 "2007-07-11T23:46:34Z")

</div>

I don’t think you can get the column back from the edited signal(At  
least not as far as I can see). I think you’ll be stuck using multiple  
renderers unless you do something fancy like catching the column from a  
button press event.

Maybe something like (Untested and probably buggy):

@column = nil

mytreeview.signal\_connect(“button-press-event”) do |treeview, event|  
if(event.event\_type == Gdk::Event::BUTTON2\_PRESS and event.button ==  
1)  
[1, 2, 3, 4].each do |i| #1, 2, 3, 4 are the editable columns.  
rect = treeview.get\_cell\_area(nil, treeview.get\_column(i))  
@column = i if(!(event.x \> rect.x and event.x \< rect.x +  
rect.width))  
end  
end  
end

…

e\_rendr.signal\_connect(“edited”, mymodel) do |rendr,row,new\_text, model|  
if(new\_text != model.get\_iter(row)[@column])  
model.get\_iter(row)[@column]=new\_text  
end  
end

Conan

Alex wrote:

> In the example that comes with ruby-gtk:  
> editable\_cells.rb
> 
> each column gets its own renderer and each renderer is given a column  
> number so that when the renderer gets the ‘edited’ signal, it already  
> knows which data is being edited because it can get the iterator [row]  
> and it already knows the column number.
> 
> So I’m wondering, is there any way to re-use renderers for many  
> columns yet still allow the data to be editable? If so, how can I get  
> the column number for the cell that is being edited in an ‘edited’  
> signal handler?
> 
> btw, the docs say: “Typically, one cell renderer is used to draw many  
> cells on the screen. To this extent, it isn’t expected that a  
> CellRenderer keep any permanent state around.”
> 
> -Alex
> 
> * * *
> 
> This [SF.net](http://SF.net) email is sponsored by DB2 Express  
> Download DB2 Express C - the FREE version of DB2 express and take  
> control of your XML. No limits. Just data. Click to get it now.  
> [http://sourceforge.net/powerbar/db2/](http://sourceforge.net/powerbar/db2/)
