Spread Windows Forms 13.0 Product Documentation
Spread Windows Forms 13.0 Product Documentation / Developer's Guide / Customizing Interaction with Cell Types / Working with Editable Cell Types / Setting a GcMask Cell
In This Topic
    Setting a GcMask Cell
    In This Topic

    You can use a GcMask cell to limit the characters a user can type in a cell. You can specify literal characters and the pattern for the characters the user is allowed to enter.

    The following image displays a pattern of three characters, followed by a single literal, and then a pattern of four characters.

    GcMask cell example

    Use the MaskPatternFieldInfo class to specify the pattern you want to use for the characters in the cell. Use the MaskLiteralFieldInfo to specify the literal characters for the mask. Use the MaskFieldInfo class to specify the order of the pattern and literal objects. You can specify a collection of pre-defined values with the MaskEnumerationFieldInfo class.

    The following image displays the available pattern characters as shown in the designer.

    An image describing available pattern characters

    The following table lists the single-byte character-set available for the pattern:

    Character(s) Description
    \A Matches any upper case alphabetical letter [A-Z].
    \a Matches any lower case alphabetical letter [a-z].
    \D Matches any decimal digit [0-9].
    \B Matches binary digit [0-1].
    \X Matches hexadecimal value [0-9A-Fa-f].
    \W Matches any word character [a-zA-Z_0-9].
    \K Matches SBCS Katakana
    \H Matches all SBCS characters.
    \N Matches all SBCS big Katakana.

    The following table lists the double-byte character-set available for the pattern:

    Character(s) Description
    \A Matches any upper case DBCS alphabetical character [A-Z].
    \a Matches any lower case DBCS alphabetical character [a-z].
    \D Matches any DBCS decimal digit [0-9].
    \B Matches DBCS binary digits [0-1].
    \X Matches DBCS hexadecimal digits [0-9 A-F a-f].
    \W Matches any DBCS word character [a-z A-Z_0-9].
    \K DBCS Katakana
    \J Hiragana
    \Z All DBCS characters.
    \N Matches DBCS big Katakana.
    \G Matches DBCS big Hiragana.
    \T Matches four-bit characters.

    For a complete list of properties and methods for the GcMask cell, refer to the GcMaskCellType class.

    Using Code

    1. Define the GcMask cell by creating an instance of the GcMaskCellType class.
    2. Set the pattern or literal characters.
    3. Set properties for the class.
    4. Assign the cell type to a cell or range of cells by setting the CellType property for a cell, column, row, or style to the GcMaskCellType object.

    Example

    This example creates a GcMask cell.

    C#
    Copy Code
    GrapeCity.Win.Spread.InputMan.CellType.GcMaskCellType gcMask = new GrapeCity.Win.Spread.InputMan.CellType.GcMaskCellType();

    GrapeCity.Win.Spread.InputMan.CellType.Fields.MaskPatternFieldInfo mpf = new GrapeCity.Win.Spread.InputMan.CellType.Fields.MaskPatternFieldInfo("\\D{3}", 3, 3);
    mpf.AutoConvert = true;
    mpf.BackColor = Color.Beige;
    mpf.ForeColor = Color.DarkOliveGreen;
    mpf.Font = SystemFonts.DefaultFont;
    mpf.Name = "MaskPatternFieldInfo";
    mpf.Padding = new System.Windows.Forms.Padding(3);

    GrapeCity.Win.Spread.InputMan.CellType.Fields.MaskLiteralFieldInfo mlf = new GrapeCity.Win.Spread.InputMan.CellType.Fields.MaskLiteralFieldInfo("-");
    mlf.BackColor = Color.Aqua;
    mlf.ForeColor = Color.Black;
    mlf.Margin = new System.Windows.Forms.Padding(4);
    mlf.Name = "MaskLiteralFieldInfo";

    GrapeCity.Win.Spread.InputMan.CellType.Fields.MaskPatternFieldInfo mlf2 = new GrapeCity.Win.Spread.InputMan.CellType.Fields.MaskPatternFieldInfo("\\D{4}", 4, 4);
    mlf2.BackColor = Color.Aqua;
    mlf2.ForeColor = Color.Black;
    mlf2.Margin = new System.Windows.Forms.Padding(4);
    mlf2.Name = "MaskLiteralFieldInfo2";

    gcMask.Fields.AddRange(new GrapeCity.Win.Spread.InputMan.CellType.Fields.MaskFieldInfo[] { mpf, mlf, mlf2});
    gcMask.PaintByControl = true;
    gcMask.PromptChar = '#';
    gcMask.RecommendedValue = "1234567";
    gcMask.ShowRecommendedValue = true;

    fpSpread1.ActiveSheet.Cells[0, 0].CellType = gcMask;
    VB
    Copy Code
    Dim gcMask As New GrapeCity.Win.Spread.InputMan.CellType.GcMaskCellType()

    Dim mpf As New GrapeCity.Win.Spread.InputMan.CellType.Fields.MaskPatternFieldInfo("\D{3}", 3, 3)
    mpf.AutoConvert = True
    mpf.BackColor = Color.Beige
    mpf.ForeColor = Color.DarkOliveGreen
    mpf.Font = SystemFonts.DefaultFont
    mpf.Name = "MaskPatternFieldInfo"
    mpf.Padding = New System.Windows.Forms.Padding(3)

    Dim mlf As New GrapeCity.Win.Spread.InputMan.CellType.Fields.MaskLiteralFieldInfo("-")
    mlf.BackColor = Color.Aqua
    mlf.ForeColor = Color.Black
    mlf.Margin = New System.Windows.Forms.Padding(4)
    mlf.Name = "MaskLiteralFieldInfo"

    Dim mlf2 As New GrapeCity.Win.Spread.InputMan.CellType.Fields.MaskPatternFieldInfo("\D{4}", 4, 4)
    mlf2.BackColor = Color.Aqua
    mlf2.ForeColor = Color.Black
    mlf2.Margin = New System.Windows.Forms.Padding(4)
    mlf2.Name = "MaskLiteralFieldInfo2"

    gcMask.Fields.AddRange(New GrapeCity.Win.Spread.InputMan.CellType.Fields.MaskFieldInfo() {mpf, mlf, mlf2})
    gcMask.PaintByControl = True
    gcMask.PromptChar = "#"
    gcMask.RecommendedValue = "1234567"
    gcMask.ShowRecommendedValue = True

    fpSpread1.ActiveSheet.Cells(0, 0).CellType = gcMask

    Using the Spread Designer

    1. Select the cell or cells in the work area.
    2. In the property list, in the Misc category, select CellType. From the drop-down list, choose the GcMask cell type. Now expand the CellType property and various properties are available that are specific to this cell type. Select and set those properties as needed.

      Or right-click on the cell or cells and select Cell Type. From the list, select GcMask. In the CellType editor, set the properties you need. Click Apply.

    3. From the File menu choose Apply and Exit to apply your changes to the component and exit Spread Designer.
    See Also