How is wxGRID_FLOAT_FORMAT_COMPACT set for a cell?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
spflanze
Earned some good credits
Earned some good credits
Posts: 130
Joined: Tue Feb 15, 2011 10:02 pm

How is wxGRID_FLOAT_FORMAT_COMPACT set for a cell?

Post by spflanze »

I have wxGrid type objects that contain floating point data I want displayed in the wxGRID_FLOAT_FORMAT_COMPACT format described here:
http://docs.wxwidgets.org/3.0/interface ... 0a024d1105

From what I have read, to set this for a cell I need to get a pointer to the cell's wxGridCellAttr object by using wxGrid::GetCellAttr() . Here is an abbreviated code excerpt I attempted to use to do this:

Code: Select all

void PartDataGridInit(
  wxGrid * pGrid, /**< The grid to be initialized */
  int ReadOnlyCols /**< The number of right most columns that are to be
                    read only. */
  )
{
  int c, r, Cols, Rows;
  wxGridCellAttr * pAttr;
  wxGridCellFloatEditor Editor;

  Cols = pGrid->GetNumberCols();
  Rows = pGrid->GetNumberRows();
  for(c=0; c<Cols - ReadOnlyCols; c++)
  { pGrid->SetColFormatFloat(c);
    for( r=0; r<Rows; r++)
    {
      pAttr = pGrid->GetCellAttr(r,c);
    }
  }
The compiler error message I get is:
C:\wxWidgets-3.0.3\include\wx\generic\grid.h|2005|error: 'wxGridCellAttr* wxGrid::GetCellAttr(int, int) const' is protected|

I looked at wxGrid::GetCellAttr()'s declaration and sure enough it is protected. How am I supposed to be able to set wxGRID_FLOAT_FORMAT_COMPACT for a cell? Will I have to derive my own class from wxGrid to do this?
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: How is wxGRID_FLOAT_FORMAT_COMPACT set for a cell?

Post by doublemax »

Try wxGrid::GetOrCreateCellAttr
http://docs.wxwidgets.org/3.0/classwx_g ... 40ff97bdff

Code: Select all

wxGridCellFloatEditor Editor;
///
pAttr->SetEditor(&Editor);
This will probably not work, the editor must be created on the heap. And beware of the reference counting (calling DecRef() / IncRef() manually). I've never used wxGrid myself, but i know it's a common pitfall.
Use the source, Luke!
Post Reply