<< Return to Main Index

< Return to Class Index

class CGXMaskControl: public CGXStatic

CGXMaskControl lets you add formatted input capabilities for cells. 

You can apply the mask control to cells with SetStyleRange, as for example

      SetStyleRange(CGXRange(5,5,10,10),
          CGXStyle()
          .SetControl(GX_IDS_CTRL_MASKEDIT)
          .SetUserAttribute(GX_IDS_UA_INPUTMASK, _T("###-###"))
          .SetUserAttribute(GX_IDS_UA_INPUTPROMPT, _T("_"))
          .SetValue("123456");

This will display “123-456” in the cells.

The default id for CGXMaskControl controls is GX_IDS_CTRL_MASKEDIT.

Style attributes which specify the appearance of the cell are:

The following attributes are not supported for CGXMaskControl cells:

CGXMaskControl fully supports find and replace and copy/paste. Insert mode is also supported and is toggled on/off when the user presses the ‘VK_INSERT’ key.

Note

The mask characters are not stored in the cell value. For example, if the user has entered a phone number such as (919) 321-6186, the cell value will be the string: “9193216186”. Call GetControlText if you want to determine the string as it is displayed in the cell.

If you want to assign a value to the cell, you should call SetValueRange with the string “9193216186”. Call SetControlText if you want to set the string as it is displayed in the cell.

If you copy or paste cells with other applications in CF_TEXT format, the text will be copied as it is displayed in the cell.

Masks

Masks consist of ‘mask characters’ and literals.  Literals are characters that appear unchanged in the mask, while mask characters specify a spot in the mask edit that accepts certain characters.  The valid mask characters and their meanings are:

Width1Width3Width1980 Width3Width4950 Mask Character Input allowed for that fieldWidth1Width3Width1980 Width3Width4950
Width1Width3Width1980 Width3Width4950 # Numeric data (0-9)Width1Width3Width1980 Width3Width4950
A Alphanumeric data (0-9 and a-Z)Width1Width3Width1980 Width3Width4950
& Any ASCII characterWidth1Width3Width1980 Width3Width4950
? Alphabetic data (a-Z)Width1Width3Width1980 Width3Width4950
U Accepts a-Z, forces to A-Z (uppercase)Width1Width3Width1980 Width3Width4950
L Accepts a-Z, forces to a-z (lowercase)Width1Width3Width1980 Width3Width4950
Width1Width3Width1980 Width3Width4950 \ Escape character.  Use this character if you would like one of the above to be interpreted as a literal character (e.g., shown in the mask)Width1Width3Width1980 Width3Width4950

Here are some examples of popular masks:

Width1Width3Width2520 Width3Width2520 Width3Width1980 Name Mask ExampleWidth1Width3Width2520 Width3Width2520 Width3Width1980
Width1Width3Width2520 Width3Width2520 Width3Width1980 Date ##/##/## 12/24/95Width1Width3Width2520 Width3Width2520 Width3Width1980
Time ##:## UU 12:35 AMWidth1Width3Width2520 Width3Width2520 Width3Width1980
Social Security Number ###-##-#### 148-92-1532Width1Width3Width2520 Width3Width2520 Width3Width1980
Phone: (###) ###-####  [####] (919) 321-6186 7Width1Width3Width2520 Width3Width2520 Width3Width1980
Zip code + 4: #####-#### 27858-1203Width1Width3Width2520 Width3Width2520 Width3Width1980
Width1Width3Width2520 Width3Width2520 Width3Width1980 First Name ???????????????? BartholomewWidth1Width3Width2520 Width3Width2520 Width3Width1980

At run time the mask characters are replaced with the prompt character which is a space by default.  The prompt character can be changed via the GX_IDS_UA_INPUTPROMPT user attribute.

Validation is not performed on the various ‘types’ of data.  For example, the CGXMaskControl will not detect that 12/35/95 is an invalid date, because while this data fits the requirements of the mask, it is invalid for a US date format. You can add this validation by overriding the OnValidateCell method.

If you want to customize the class behavior and add special mask characters, you have to subclass the CGXMaskData class. See the description for CGXMaskData for more information.

#include <gxall.h>

See Also

CGXMaskData CGXGridCore::OnValidateCell CGXGridCore::SetValueRange CGXControl::GetControlText

CGXMaskControl

Class Members