How do I set up a normal edit cell to accept only numbers?
You have to subclass CGXEditControl and override the ValidateString() member. Every time the user inserts a character, ValidateString() will be called. If you return FALSE, the character will be ignored.
Example:
BOOL CNumericEditControl::ValidateString(const CString& sEdit)
{
// cycle through string and check each character if it is a digit
for (int n = 0; n < sEdit.GetLength(); n++)
{
if (!isdigit(sEdit[n]) && sEdit[n] != '.')
return FALSE;
}
return TRUE;
}
NOTE:
The masked edit control makes it much easier to limit user input. Check out the class reference for CGXMaskControl. You will not have to derive a class from CGXEditControl anymore.