Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
875
Simple input masks at the WinGrid cell level
posted

Hi,

We're using WinGrid as a base class for a control that can contain a different data type in each cell. So each column isn't tied to just one data type. I need to support simple input masks (like "(xxx) xxx-xxxx" for a phone number) at the individual cell level.

I've found a few examples that show setting MaskInput, MaskDataMode, MaskClipMode, and MaskDisplayMode at the column level. I couldn't find any examples of how to do something like this as the individual cell level. (I even tried adding an UltraMaskedEdit as the editor control but that blew up; apparently it's not supported as a cell editor.)

I'm setting an UltraTextEditor as the editor for cells that need a mask in the OnAfterCellActivate() override (which is where I set up all the cell-specific stuff before editing since each cell can be any data type). I also tried setting the column-level masking in there, but I don't see any result from doing that, it's like there's no mask at all. Here's a snippet of the code from the OnAfterCellActivate() override that deals with masked text cells:

else if (CurrentItem.DataType == DataTypes.MaskedText)
{
    _maskedTextEditor.MaxLength = CurrentItem.MaxLength;
    ActiveCell.Column.MaskInput = CurrentItem.InputMask;
    ActiveCell.Column.MaskDataMode = Infragistics.Win.UltraWinMaskedEdit.
MaskMode
.Raw;
    ActiveCell.Column.MaskClipMode= Infragistics.Win.UltraWinMaskedEdit.
MaskMode
.IncludeBoth;
    ActiveCell.Column.MaskDisplayMode = Infragistics.Win.UltraWinMaskedEdit.
MaskMode
.IncludeBoth;
    _maskedTextEditor.ReadOnly = CurrentItem.ReadOnly;
}

The Mask* settings here don't seem to have any effect. I'm not sure if that's because I'm using an UltraTextEditor as the cell editor (_maskedTextEditor, set outside of this code snippet), or if I'm setting this at the wrong time in the eventing, or what.

I'm also concerned that I'm setting the masked stuff at the column level when I really need the masking at the individual cell level. Each column can contain any number of cells of different data types.

I looked at data filters, but I need the masked literals available both during input and also stored in the database. Seems like a data filter is used to translate the form between input and the data layer.

Do I have any options here? Thanks in advance,

Jim Honeycutt

Parents
No Data
Reply
  • 469350
    Offline posted

     Hi Jim,

    Jim Honeycutt said:
    I even tried adding an UltraMaskedEdit as the editor control but that blew up; apparently it's not supported as a cell editor.

    UltraMaskedEdit is an editor so you can assign it as the EditorControl of a column or cell. Not sure why it was blowing up for you. 

    Anyway, the reason this isn't working is that the grid settings for the Mask* properties (or almost any properties, really) override any settings on the editor. In other words, any time the grid already has a property to control something, it uses it's own property settings before it uses the editor. 

    However, in the case of masks, you can change this by setting UseEditorMaskSettings on the column to true. This will reverse the order of precedence and allow a cell to use the editor mask properties before the grid column's settings.

    I probably would not recommend assigning the editor or editor control in AfterEnterEditMode, though. This event is too late and by the time this fires, the cell has already entered edit mode with the editor it already had. You should use InitializeRow or BeforeCellActivate.

Children