# Grid Cell Background Colour

**URL:** <https://www.ruby-forum.com/t/grid-cell-background-colour/219840>\
**Category:** wxRuby\
**Created:** [May 18, 2012, 12:02am UTC](https://www.ruby-forum.com/t/grid-cell-background-colour/219840 "2012-05-18T00:02:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [May 18, 2012, 12:02am UTC](https://www.ruby-forum.com/t/grid-cell-background-colour/219840/1 "2012-05-18T00:02:10Z")

</div>

On to my next question. 🙂

I’ve been trying to get the cell background colour to work for a  
Wx::Grid  
control. Setting a default background colour works, but using the  
set\_cell\_background\_colour method for an individual cell doesn’t.  
Following is a short snippet of what I’m trying to do (essentially  
highlight cells that don’t match):

columnNames = Array.[](“Col1”, “Col2”, “Col3”)  
row1 = Array.[](“A”, “B”, “C”)  
row2 = Array.[](“X”, “Y”, “Z”)  
resultSet = Array.[](row1, row2)

table = Table.new(columnNames, resultSet)  
grid = Wx::Grid.new(panel, -1)  
grid.set\_table(table)  
@grid.set\_cell\_background\_colour(1, 1, Wx::RED)

Any help is greatly appreciated.

Norbert

---

<div class="post-metadata">

**Author:** ![norbertl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c77e96/32.png) [@norbertl](https://www.ruby-forum.com/u/norbertl)\
**Post date:** [May 18, 2012, 12:21am UTC](https://www.ruby-forum.com/t/grid-cell-background-colour/219840/2 "2012-05-18T00:21:36Z")

</div>

I should probably also have mentioned, the Table object is derived from  
Wx::GridTableBase.

---

<div class="post-metadata">

**Author:** ![norbertl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c77e96/32.png) [@norbertl](https://www.ruby-forum.com/u/norbertl)\
**Post date:** [May 18, 2012, 7:15pm UTC](https://www.ruby-forum.com/t/grid-cell-background-colour/219840/3 "2012-05-18T19:15:49Z")

</div>

Update: I finally got this working. In case anyone else runs into the  
same thing, I finally realized I needed to override the set\_attr and  
get\_attr methods in my Table subclass.

Norbert
