True DBGrid for WinForms | ComponentOne
Cells / Cell Editing / Input Masking
In This Topic
    Input Masking
    In This Topic

    True DBGrid for WinForms provides an EditMask property that optionally works with the NumberFormat property to ensure input masking and consistent data entry.

    Specify an Input Mask for Column

    The EditMask property of the C1DataColumn object is used to specify an input mask template for end-user data entry. The input mask string is composed of special characters that represent either an input character that the user must enter.

    The EditMask must be a string composed of the following symbols:

    1. Wildcards

      0          digit

      9          digit or space

      #          digit or sign

      L          letter

      ?          letter or space

      A          letter or digit

      a          letter, digit, or space

      &          any character

    2. Localized characters

      .          localized decimal separator

      ,          localized thousand separator

      :          localized time separator

      /          localized date separator

    3. Command characters

      \          next character is taken as a literal

      >          translate letters to uppercase

      <          translate letters to lowercase

    For example:

    C#
    Copy Code
    // Set the mask so the user can enter a phone number, with optional area code, and a state in capitals
    this.c1TrueDBGrid1.Columns[0].EditMask = "(###) 000-0000 St\\ate\\: >LL";
    

    Using an Input Mask for Formatting

    Whereas the EditMask property is used to specify an input mask for data entry, the NumberFormat property is used to specify the display format of data in a grid cell. If the NumberFormat property of the column is not specified, the grid simply displays the cached text (stripped of literals) as is; if the NumberFormat property is specified, the grid sends the cached text to the display formatter.

    Since it is common for the input and display formats to be the same, the NumberFormat property has an Edit Mask option. If this option is selected, then the EditMask property setting will be used for both data input and display. However, the input and display formats need not be the same, so a NumberFormat option that differs from the EditMask property can be selected.

    Normally, after the user finishes editing a cell in a column which has its EditMask property set, True DBGrid for Winforms caches the modified cell text, but any literal characters in the input mask template will be stripped from the modified cell text beforehand. However, this behavior can be overridden with the EditMaskUpdate property.

    By default, the EditMaskUpdate property is False. This means that when the modified cell text is updated to the database, the grid sends the cached text (stripped of literals), not the formatted text displayed in the cell. Override this default behavior by setting the EditMaskUpdate property to True, which causes the cached text to be formatted according to the EditMask property before being updated to the database.

    Therefore, it is important to set EditMaskUpdate properly to ensure that the correct data is sent to the database for update.