SetCellValue crash Topic is solved

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
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

SetCellValue crash

Post by mael15 »

hi everyone,
i have a wxGrid cell with a wxGridCellNumberEditor and have a special case where i do not only have an int in that cell of the grid, but i want to show i.e. "45±" instead of just "45".
now, it is no problem to remove the "±" before the editor is shown with wxEVT_GRID_EDITOR_SHOWN event, but the other way round crashes in the handler of the wxEVT_GRID_EDITOR_HIDDEN event. the simple

Code: Select all

SetCellValue(2, 2, "45±") 
does not work here like it does when I init the cell before clicking on it, because now when the editor is closing, it enters the last part here:

Code: Select all

void wxGrid::SetCellValue( int row, int col, const wxString& s )
{
    if ( s == GetCellValue(row, col) )
    {
        // Avoid flicker by not doing anything in this case.
        return;
    }

    if ( m_table )
    {
        m_table->SetValue( row, col, s );
        if ( ShouldRefresh() )
        {
            int dummy;
            wxRect rect( CellToRect( row, col ) );
            rect.x = 0;
            rect.width = m_gridWin->GetClientSize().GetWidth();
            CalcScrolledPosition(0, rect.y, &dummy, &rect.y);
            m_gridWin->Refresh( false, &rect );
        }

	// HERE
        if ( m_currentCellCoords.GetRow() == row &&
             m_currentCellCoords.GetCol() == col &&
             IsCellEditControlShown())
             // Note: If we are using IsCellEditControlEnabled,
             // this interacts badly with calling SetCellValue from
             // an EVT_GRID_CELL_CHANGE handler.
        {
            HideCellEditControl();
            ShowCellEditControl(); // will reread data from table
        }
    }
}
and crashes with a formatting error "cell does not have numeric value".
can I do anything about it?
User avatar
doublemax
Moderator
Moderator
Posts: 19115
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: SetCellValue crash

Post by doublemax »

Can't you move the "special treatment" from wxEVT_GRID_EDITOR_HIDDEN to wxEVT_GRID_CELL_CHANGED event handler?
Use the source, Luke!
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: SetCellValue crash

Post by mael15 »

YES!!! worked, that was easy, should have thought of it myself. =D>
thank you!
Post Reply