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
This is a pretty long thread. Can you be more specific about which problem you are referring to?
Even i'm facing same problem. Any solution for this ?
Mike,
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