Back to Devexpress

RepositoryItemTextEdit.MaskSettings Property

windowsforms-devexpress-dot-xtraeditors-dot-repository-dot-repositoryitemtextedit-33375b9a.md

latest5.7 KB
Original Source

RepositoryItemTextEdit.MaskSettings Property

Provides access to settings that allow you to create input masks.

Namespace : DevExpress.XtraEditors.Repository

Assembly : DevExpress.XtraEditors.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
[DXCategory("Format")]
public virtual MaskSettings MaskSettings { get; }
vb
<DXCategory("Format")>
Public Overridable ReadOnly Property MaskSettings As MaskSettings

Property Value

TypeDescription
DevExpress.XtraEditors.Mask.MaskSettings

Mask settings.

|

Remarks

The MaskSettings property allows you to set up input masks at design time and in code.

At Design Time

In the Visual Studio Property Grid, click the ellipsis button next to the MaskSettings property. In the “Mask Settings” dialog that pops up, select the required mask type and choose any of the predefined expressions.

If there is no ready-to-use expression that fits your needs, click “Create New Mask…” and combine metacharacters to create a custom expression.

To specify additional mask settings, tick the corresponding checkbox at the bottom left corner of a dialog. Available settings depend on the active mask type.

In Code

To set up a mask expression and configure mask settings in code, use the MaskSettings.Configure method. This method requires that you specify one of the following types defined in the DevExpress.Data.Mask.Internal namespace:

  • MaskSettings.Numeric
  • MaskSettings.DateOnly
  • MaskSettings.TimeOnly
  • MaskSettings.DateTime
  • MaskSettings.DateTimeOffset
  • MaskSettings.TimeSpan
  • MaskSettings.Simple
  • MaskSettings.Regular
  • MaskSettings.RegExp

For example, the following code applies a numeric mask that allows users to enter decimal numbers in the “000.00” format, and specifies two additional settings: hides zeros that do not affect the value (“0.9” instead of “0.9”), and shows a decimal separator even when the fractional part is 0 (“110.” instead of “110”).

csharp
using DevExpress.XtraEditors.Mask;

//Fluent API
textEdit5.Properties.MaskSettings.Configure<MaskSettings.Numeric>(settings => {
    settings.MaskExpression = "##0.##";
    settings.AutoHideDecimalSeparator = false;
    settings.HideInsignificantZeros = true;
});

//regular API
var settings = textEdit5.Properties.MaskSettings.Configure<MaskSettings.Numeric>();
settings.MaskExpression = "##0.##";
settings.AutoHideDecimalSeparator = false;
settings.HideInsignificantZeros = true;
vb
Imports DevExpress.XtraEditors.Mask

'Fluent API
Private textEdit5.Properties.MaskSettings.Configure(Of MaskSettings.Numeric)(Sub(settings)
    settings.MaskExpression = "###.##"
    settings.AutoHideDecimalSeparator = False
    settings.HideInsignificantZeros = True
End Sub)

'regular API
Private settings = textEdit5.Properties.MaskSettings.Configure(Of MaskSettings.Numeric)()
settings.MaskExpression = "###.##"
settings.AutoHideDecimalSeparator = False
settings.HideInsignificantZeros = True

At the Data Source Layer

If your editor is bound to a field of a code-first data source, you have a third option to apply input masks: decorate data class properties with “…EditMask” attributes. An editor bound to this field applies a mask of the required type, and sets up additional options you specified as attribute parameters.

For example, the following code applies two masks:

  • a RegEx type mask that accepts any number of literals and automatically capitalizes the first character. The AllowBlankInput parameter allows users to leave this editor empty, and the disabled ShowPlaceholders hides placeholders.

  • a DateTime type mask that displays dates in the short “MM/DD/YYYY” format.

  • C#

  • VB.NET

csharp
public class Employee {
    [RegExEditMask("[A-Z][a-z]+", AllowBlankInput = true, ShowPlaceholders = false)]
    public string FirstName { get; set; }
    [EditMask("d")]
    public DateTime HiredAt { get; set; }
}
vb
Public Class Employee
    <RegExEditMask("[A-Z][a-z]+", AllowBlankInput := True, ShowPlaceholders := False)>
    Public Property FirstName() As String
    <EditMask("d")>
    Public Property HiredAt() As Date
End Class

The list below enumerates available data attributes. All attributes are declared in the System.ComponentModel.DataAnnotations namespace and stored in the DevExpress.Data assembly.

  • NumericEditMask
  • DateOnlyEditMask
  • TimeOnlyEditMask
  • DateTimeEditMask
  • DateTimeOffsetEditMask
  • TimeSpanEditMask
  • SimpleEditMask
  • RegularEditMask
  • RegExEditMask

The EditMask attribute can be used instead of any of these attributes. It exposes only basic mask settings, and applies a mask type that fits the type of a property. For example, in the code sample above the attribute applies the DateTime mask because the “HiredAt” property is of the DateTime type.

See Also

RepositoryItemTextEdit Class

RepositoryItemTextEdit Members

DevExpress.XtraEditors.Repository Namespace