[wxPython-users] wx.grid.GridCellBoolRenderer

Robin Dunn robin at alldunn.com
Wed Jan 2 16:54:09 PST 2008


Mark Erbaugh wrote:
> I'm trying to use a GridCellBoolRenderer.  According to wxPIA, this
> renderer should show a checkbox in the middle of the cell that is
> checked for a True value and un-checked for False.
> 
> I get a checkbox at the left side of the cell and the only way I can get
> it checked is by putting a value of 1 (integer) in the cell.  I can
> change the alignment by using a GridCellAttr, but is there a way to get
> the renderer to respect bool values?

It's boolean in the sense of zero and non-zero, not necessarily Python 
True and False singletons. It also depends on the data type used in the 
table for that cell.  For example if the default string table is used 
then the bool renderer will actually be comparing values to "" and "1". 
  Here is the code:

     bool value;
     if ( grid.GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) )
     {
         value = grid.GetTable()->GetValueAsBool(row, col);
     }
     else
     {
         wxString cellval( grid.GetTable()->GetValue(row, col) );
         value = wxGridCellBoolEditor::IsTrueValue(cellval);
     }


> 
> Also, is using a GridCellAttr the only way to set the alignment of an
> entire column (other than doing a SetCellAlignment on each cell)?  It
> seems like there should be a SetColumnAlignment method.

If there was such a method all it would do is set the column attribute 
with a GridCellAttr.


-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!




More information about the wxpython-users mailing list