I would like to use a virtual wxGrid. While the display of values works fine so far, I have some problems with editing cells. More specifically: Editing itself seems to work (I can enter a string into the cell for instance), but wxGridTableBase::SetValue is never called. Maybe someone has a hint of what to check? I guess it's something really stupid...
MTIA,
smf
Code: Select all
class GridTable : public wxGridTableBase
{
public:
// ... some setup-stuff removed, to keep this shorter...
wxString GetValue(int row, int col)
{
wxString returnText(_("--"));
if( (int)m_Data.size() > col &&
(int)m_Data[0].size() > row )
{
enum GridData::TYPE type;
type = m_Data[col][row].getType();
bool isValid;
isValid = m_Data[col][row].isValid();
if( isValid )
{
switch( type )
{
case( GridData::TYPE_FLOAT ):
{
returnText.Printf( _("%3.2f %s"),
m_Data[col][row].getFloatValue(),
m_Data[col][row].getUnit() );
}
default:
{
returnText.Printf( _("--- %s"),
m_Data[col][row].getUnit() );
}
}
}
}
return( returnText );
};
wxString GetTypeName( int row, int col )
{
return( wxGRID_VALUE_STRING );
}
bool CanSetValueAs( int row, int col, const wxString& typeName )
{
if( typeName == wxGRID_VALUE_STRING )
{
return( true );
}
return( false );
}
void SetValue(int row, int col, wxString const& value )
{
if( (int)m_Data.size() > col &&
(int)m_Data[0].size() > row )
{
enum GridData::TYPE type;
type = m_Data[col][row].getType();
switch( type )
{
case( GridData::TYPE_FLOAT ):
{
double number;
if( value.ToDouble(&number) )
{
m_Data[col][row].setFloatValue( number );
}
m_Data[col][row].setFloatValue( 3.1415926 );
}
default:
{
m_Data[col][row].invalidate();
}
}
}
};
int GetNumberRows()
{
if( m_Data.size() > 0)
{
return( m_Data[0].size() );
}
return( 0 );
}
int GetNumberCols()
{
return( m_Data.size() );
}
wxString GetRowLabelValue( int row )
{
if( m_Data.size() > 0 &&
row < m_Data[0].size() )
{
return( m_Data[0][row].getName() );
}
return( _("") );
}
private:
std::vector<std::vector<GridData>>& m_Data;
};