I am trying to format an Australian phone number with the UltraMaskedEdit control in the following way
nnnn nnn nnn
9999 999 999
#### ### ###
I can input using any of these input masks, but the phone numbers in Australia have leading zeroes i.e. 0419 999 999. Since the user must dial the zero, I need the leading zero to be displayed.
How can I input this number and not have the data in the control shift left because of the leading zero? The data is defined as a numeric with 11 digits total.
Keep in mind that the application must also store U.S. phone numbers also.
Thanks
Larry Burns
Hi Larry,
My guess is that you probably need to adjust the MaskDisplayMode and tell it to include literals and padding.
With e.Layout.Bands(0)
.Columns("ssn").Format = "###-##-####"
.Columns("ssn").CellAppearance.TextHAlign = HAlign.Right
.Columns("phone1").MaskInput = "9999 999 999"
.Columns("phone1").Format = "9999 999 999"
With .Columns("Phone1")
.MaskDataMode = Infragistics.Win.UltraWinMaskedEdit.MaskMode.IncludeLiteralsWithPadding
.MaskClipMode = Infragistics.Win.UltraWinMaskedEdit.MaskMode.IncludeLiteralsWithPadding
.MaskDisplayMode = Infragistics.Win.UltraWinMaskedEdit.MaskMode.IncludeLiteralsWithPadding
End With
Hi,
Your original post was referring to the UltraMaskedEdit control, but now you seem to be referring to a WinGrid column.
Are you still unable to get this to work?
What's the data type of the column?
Mike,
Sorry about that! Yes I switched gears on you. The data was a numeric in SQL Server. In order to display the leading zero using 9999 999 999 (Australian phone numbers), I had to change the column to a string and format worked for the maskededit control.
The issue now is displaying those same numbers in a grid using the format. The last post shows what I am doing with format for both a SSN and those phone numbers. Neither will display properly with any format or maskinput properties I set.
FYI: The SSN is a numeric with 9 digits.
Any suggestions?
Okay, so I still don't know what data type you are working with here. What's the DataType of the grid column?
I have a ultramaskedEdit. i didn't set any thing in mask input because user wants to type letter and numbers both.
Now my issue is when ever user clicks in ultramasked editor cursor stops there and user has to start type from there.
Is there ay way whereever user click anywhere in ultramasked editor the focus starts from left same like ultratexteditor.
Both fields are strings in the grid? That seems a bit off for a Numeric field, but I guess maybe they do that since it's fixed-length and it's not like you would ever want to perform any mathematical operations on an SSN. But using strings to deal with numbers is never a good idea and will cause all sorts of problems with sorting, filtering, and in this case, formatting.
Anyway, the way the Format property work is that the grid takes the Value of the cells and calls the ToString method on it and passes in the Format. This will not do anything for a string field, because the String DataType in DotNet doesn't have any support for formatting.
So I tried this out using a string value like the one you posted above: "0419 999 999"
This, of course, works fine, since the data contains the leading zero. But if I remove the leading zero from the data source: "419 999 999", it doesn't show it in the grid cell. So my guess is that the zero is being stripped out when the Numeric SQL data is translated into a string in your data source.
I don't see any way the grid can deal with this using a string type. At least not with a Mask. The only way I can think of to get the behavior you want here is to use a DataFilter. Search the forums for IEditorDataFilter and you can find lots of example code to point you in the right direction. In this case, you will need to handle the EditorToDisplay conversion to format the string and add in the leading zeroes, and then reverse the process, stripping out the zeroes in the DisplayToEditor conversion.
Here you go.
? grdcustomer.DisplayLayout.Bands(0).Columns("ssn").DataType
{Name = "String" FullName = "System.String"}
System.RuntimeType: {Name = "String" FullName = "System.String"}
? grdcustomer.DisplayLayout.Bands(0).Columns("phone1").DataType
I need to know the DotNet Types being used by the grid, not the SQL types.
Ok,
I told you in the previous post, but here it is again.
The phone number is a string ( SQL - nvarchar(11))
the SSN is a numeric (SQL - numeric[9,0))
Larry