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
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.
Hi Mike,
Thanks for the help. Whenever I assign an UltraMaskedEdit as the EditorControl for a cell, it blows up with the error below. That led me to wonder if maybe you couldn't use an UltraMaskedEdit as a cell-level editor. (In my case I have to assign editors at the cell level instead of the column level since we can have any data type in any cell.)
I just instantiate the UltraMaskEdit and assign it as the EditorControl in my OnAfterActivate override like this:
ActiveCell.EditorControl = _maskedTextEditor;
Am I doing something wrong?
Thanks for your help!Jim Honeycutt
System.Exception: The Owner specified a type to EditorWithMask that is not supported by the editor. at Infragistics.Win.UltraWinMaskedEdit.MaskInfo..ctor(EditorWithMask maskEditor, EmbeddableEditorOwnerBase owner, Object ownerContext) at Infragistics.Win.EditorWithMaskEmbeddableUIElement.SyncOwnerInfo(Boolean forceRegetValueFromOwner) at Infragistics.Win.EditorWithMaskEmbeddableUIElement.OnBeforeDraw() at Infragistics.Win.EditorWithMaskEmbeddableUIElement.PositionChildElements() at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UltraWinGrid.RowColRegionIntersectionUIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UltraWinGrid.DataAreaUIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UltraWinGrid.UltraGridUIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UIElement.DrawHelper(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Boolean clipText, Boolean forceDrawAsFocused, Boolean preventAlphaBlendGraphics) at Infragistics.Win.UIElement.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Boolean forceDrawAsFocused, Boolean preventAlphaBlendGraphics) at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Size elementSize, Boolean preventAlphaBlendGraphics) at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Size elementSize) at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode) at Infragistics.Win.UltraWinGrid.UltraGridUIElement.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode) at Infragistics.Win.UltraControlBase.OnPaint(PaintEventArgs pe) at Infragistics.Win.UltraWinGrid.UltraGrid.OnPaint(PaintEventArgs pe) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs) at System.Windows.Forms.Control.WmPaint(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
The error message indicates that the UltraMaskedEditor cannot handle the data type of the column. So you probably need to use a DataFilter and set the ExpectedType so that you can convert the cell's value into something the editor can handle.