Can you set multiple wxGrid Colum Attributes?

Petr Smilauer petrsm at jcu.cz
Wed Jan 9 13:12:00 PST 2008


Dear Bob,

>I have a wxGrid with three columns. I want all of the grid
> to be ReadOnly. If I do this:
...
> wxGridCellAttr *ReadOnlyAttr = new wxGridCellAttr;
> ReadOnlyAttr->SetReadOnly();
> m_LogGrid->SetColAttr( LogGridColDate, ReadOnlyAttr );
...
> and do not do this:
> 
> wxGridCellAttr *ColorAttr = new wxGridCellAttr;
> ColorAttr->SetBackgroundColour( default_cell_background_color );
...
> 
> the gird is ReadOnly as I want, but if I do try to set the background color
> of the grid as well, then the grid is no longer read only.

> Is it possible to set more than one attribute on a column?
Yes, you can. But your ColorAttr object contains not only the background
color settings, but also default settings for the other attributes, including
read-only flag (this is not completely accurate: it containts info that this
setting was not set, so it is taken from the grid default attribute; but
the result is all the same). 
By calling SetColAttr with ColorAttr, you have effectively
replaced the ReadOnlyAttr stored in cell attribute provider object.
 One option would be to buffer locally one cell attribute object and
change its attributes as you need (I assume change of RO status and
background colour does not happen at the same time).


> If I load my data in to the grid, which colors each cell depending on
> the data loaded I get colored cells as I want. However when
> I try to return all of the cell backgrounds back to their
> default color, when I load new data next time, the old
> colors remain. How do I restore the entire grid
> to its default background color?

What about 
m_logGrid->GetTable()->SetAttrProvider( new wxGridCellAttrProvider);

Best regards from

Petr Smilauer




More information about the wx-users mailing list