ComponentOne FlexGrid for WinForms
Masks
Using the C1FlexGrid Control > Editing Cells > Masks

The C1FlexGrid control also supports masked editing. This type of editing uses an input mask to provide a template and automatically validate the input as the user types. The mask is specified by the EditMask property, which can be used with regular text fields and with drop-down combo fields.

Mask strings have two types of characters: literal characters, which become part of the input, and template characters, which serve as placeholders for characters belonging to specific categories (for example, digits or alphabetic). For example, the code below assigns a "(999) 999-9999" editing mask to column one, which holds phone numbers (the digit "9" is a placeholder that stands for any digit):

To write code in Visual Basic

Visual Basic
Copy Code
' Set up a phone number edit mask.
_flex.Cols(1).EditMask = "(999) 999-9999"

To write code in C#

C#
Copy Code
// Set up a phone number edit mask.
_flex.Cols[1].EditMask = "(999) 999-9999";

Setting the EditMask property to a non-empty string causes it to use the built-in masked editor, even if the column contains date/time values (usually, a DateTimePicker control is used to edit these columns). This is especially convenient if you have DateTime columns that hold times only (not dates). In these cases, you can set the following properties to use a masked editor instead of the DateTimePicker control:

To write code in Visual Basic

Visual Basic
Copy Code
_flex.Cols(1).DataType = GetType(DateTime) 
_flex.Cols(1).Format = "hh:mm tt" 
_flex.Cols(1).EditMask = "99:99 LL"

To write code in C#

C#
Copy Code
_flex.Cols[1].DataType = typeof(DateTime);
_flex.Cols[1].Format = "hh:mm tt";
_flex.Cols[1].EditMask = "99:99 LL";

The EditMask property can also be set at design time using the Input Mask dialog box.


The Input Mask dialog box can be accessed through the Column Tasks menu or through the C1FlexGrid Column Editor.

Note: The Input Mask dialog box is column specific and will only change the EditMask property of the selected column.

For details on the syntax used to build the mask strings, see the EditMask property in the control reference section.

If different cells in the same column need different masks, trap the BeforeEdit event and set the EditMask property to an appropriate value for the current cell.

See Also