If the number or float editor is being used but the values are

saved/loaded to the table as strings, then allow empty strings.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16751 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2002-08-24 21:39:21 +00:00
parent 44893b87ab
commit 8a60ff0af8

View File

@@ -797,8 +797,9 @@ void wxGridCellNumberEditor::BeginEdit(int row, int col, wxGrid* grid)
} }
else else
{ {
m_valueOld = 0;
wxString sValue = table->GetValue(row, col); wxString sValue = table->GetValue(row, col);
if (! sValue.ToLong(&m_valueOld)) if (! sValue.ToLong(&m_valueOld) && ! sValue.IsEmpty())
{ {
wxFAIL_MSG( _T("this cell doesn't have numeric value") ); wxFAIL_MSG( _T("this cell doesn't have numeric value") );
return; return;
@@ -820,16 +821,20 @@ bool wxGridCellNumberEditor::EndEdit(int row, int col,
wxGrid* grid) wxGrid* grid)
{ {
bool changed; bool changed;
long value; long value = 0;
wxString text;
if ( HasRange() ) if ( HasRange() )
{ {
value = Spin()->GetValue(); value = Spin()->GetValue();
changed = value != m_valueOld; changed = value != m_valueOld;
if (changed)
text = wxString::Format(wxT("%ld"), value);
} }
else else
{ {
changed = Text()->GetValue().ToLong(&value) && (value != m_valueOld); text = Text()->GetValue();
changed = (text.IsEmpty() || text.ToLong(&value)) && (value != m_valueOld);
} }
if ( changed ) if ( changed )
@@ -837,7 +842,7 @@ bool wxGridCellNumberEditor::EndEdit(int row, int col,
if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_NUMBER)) if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_NUMBER))
grid->GetTable()->SetValueAsLong(row, col, value); grid->GetTable()->SetValueAsLong(row, col, value);
else else
grid->GetTable()->SetValue(row, col, wxString::Format(wxT("%ld"), value)); grid->GetTable()->SetValue(row, col, text);
} }
return changed; return changed;
@@ -965,8 +970,9 @@ void wxGridCellFloatEditor::BeginEdit(int row, int col, wxGrid* grid)
} }
else else
{ {
m_valueOld = 0.0;
wxString sValue = table->GetValue(row, col); wxString sValue = table->GetValue(row, col);
if (! sValue.ToDouble(&m_valueOld)) if (! sValue.ToDouble(&m_valueOld) && ! sValue.IsEmpty())
{ {
wxFAIL_MSG( _T("this cell doesn't have float value") ); wxFAIL_MSG( _T("this cell doesn't have float value") );
return; return;
@@ -979,13 +985,15 @@ void wxGridCellFloatEditor::BeginEdit(int row, int col, wxGrid* grid)
bool wxGridCellFloatEditor::EndEdit(int row, int col, bool wxGridCellFloatEditor::EndEdit(int row, int col,
wxGrid* grid) wxGrid* grid)
{ {
double value; double value = 0.0;
if ( Text()->GetValue().ToDouble(&value) && (value != m_valueOld) ) wxString text(Text()->GetValue());
if ( (text.IsEmpty() || text.ToDouble(&value)) && (value != m_valueOld) )
{ {
if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_FLOAT)) if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_FLOAT))
grid->GetTable()->SetValueAsDouble(row, col, value); grid->GetTable()->SetValueAsDouble(row, col, value);
else else
grid->GetTable()->SetValue(row, col, wxString::Format(wxT("%f"), value)); grid->GetTable()->SetValue(row, col, text);
return TRUE; return TRUE;
} }