Alright - I know I can use built-in grid properties to set an input mask on a cell, however one property I desperately need is not built into the grid, so I thought I'd get around this by using an actual UltraMaskedEdit (ume) assigned as EditorControl of the cell, but it still fails to work as planned.
What I need is the .InsertMode property of the ume to be false (overstrike mode). It works as expected on the ume control on the form, but not when assigned to the grid.
What I have done to test this is to create a new blank form, add a UltraGrid control (ug1) and a UltraMaskEdit control (ume1) to the form.
I then created a sample data table and bound it to the grid in the Form Load event.
Also in Form Load - I set the following on the UltraMaskedEdit control:
.InputMask = ">CCCCCCCC|CCCCCCCCCC|CC"
.ClipMode = UltraWinMaskedEdit.MaskMode.Raw
.DataMode = UltraWinMaskedEdit.MaskMode.Raw
.DisplayMode = UltraWinMaskedEdit.MaskMode.Raw
.InsertMode = False
.MaskLiteralsAppearance.ForeColor = Red
In the grid InitializeRow event I assign the EditorControl as follows
e.Row.Cells("PID").EditorControl = ume1
As stated above, if I click into the ume on the form, the cursor changes to the block style cursor and the data entry works in overstrike.
If I click into a grid cell that this editor is assigned to, the mask portion works, but the cursor is the thin line style and data entry continues to work in insert mode.
Perhaps I am going about things the wrong way altogether.
This particular column is a 20 char (max - typically 18 char) "Point ID" (or PID) field. Data within this PID is fixed length & position specific AND the string may contain blank spaces.
Previously I had written my own key handler events that simulated overstrike (including leaving a blank space in place of a character if you hit the backspace key) but recently something else changed either in a new release of Ultragrid or within my program code somewhere that is causing these routines to (mal)function erratically and I am at wits end trying to find it. That's why I attempted to go back and use the built-in overstrike behavior (i know I will still have to write my own backspace handler though)
My ultimate goal is to have data entry such that there are markers at the 8th & 18th character positions and these markers have no effect on any text entry but rather serve only as visual cues to where you are within the 20 character string. All data entry is in overstrike mode by default unless the user toggles it off.
Any suggestions on where I'm going wrong with the UltraMaskedEdit / Grid as well as any suggestions for a better way to accomplish this are most welcome.
Hello n2dfire,
The properties you set on the UltraMaskedEdit are being ignored by the column which is its owner.
So you could read about the following property:
http://help.infragistics.com/Help/NetAdvantage/WinForms/2011.1/CLR2.0/HTML/Infragistics2.Win.UltraWinGrid.v11.1~Infragistics.Win.UltraWinGrid.UltraGridColumn~UseEditorMaskSettings.html/.
This might help you to achieve the desired behavior. You could also set the desired properties on the column like this:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { e.Layout.Bands[0].Columns[0].MaskLiteralsAppearance.ForeColor = Color.Red; e.Layout.Bands[0].Columns[0].MaskClipMode = Infragistics.Win.UltraWinMaskedEdit.MaskMode.Raw; e.Layout.Bands[0].Columns[0].MaskDataMode = Infragistics.Win.UltraWinMaskedEdit.MaskMode.Raw; e.Layout.Bands[0].Columns[0].MaskDisplayMode = Infragistics.Win.UltraWinMaskedEdit.MaskMode.Raw; }
As to the 'InsertMode' property, you could simulate its behavior by using a similar code:
private void ultraGrid1_AfterEnterEditMode(object sender, EventArgs e) { if (ultraGrid1.ActiveCell.IsInEditMode) { SendKeys.Send("{Insert}"); } } private void ultraGrid1_AfterExitEditMode(object sender, EventArgs e) { if (ultraGrid1.ActiveCell.IsInEditMode) { SendKeys.Send("{Insert}"); } }
Please feel free to let me know if I misunderstood you or if you have any other questions.