I am loading a dataset with a field set as string. This field holds just the digits of a phone number.
I have a WinGrid on a form with the dataset assigned as the datasource. Using UltraWinGrid Designer I set the "Phone" columns Format to (###) ###-####
However when the application is ran and the gird is loaded the "Phone" column still shows just the digits. I then returned and set the "Phone" columns MaskInput value to (###) ###-####
When I run the application, again the column does not get formated, but if I click one of the Phone cells the format does show up. I plan on making this grid not to allow, edits, additions or deletions so the user will never be selected edit mode on a cell.
I just am puzzled as to why when I enter a format it is not formatting that column as expected.
When the grid cells displays the value, it calls ToString on the Value of the cell and passes in the Format you specified. The String data type does not accept any parameters to the ToString method and so strings to not support formatting.
Once you enter edit mode on the cell, the format is no longer applied, but the Mask is used.
I think you might be able to get what you want by using the MaskDisplayMode. But if that doesn't work, then you will need to use a numeric data type in order to format the data for display.
Alternately, you could use a DataFilter and manipulate the strings yourself in code.
Mike,
I'm having a similar problem. I have a column in my grid that displays numeric data [the field in thedatabase is defined as numeric(3,1)]. In the InitializeLayout event of the grid I am setting some properties of the column to display the data correctly and provide the user with an inputmask so the data is entered correctly.
I've set a breakpoint in the code and it is executing the following code, but yet when I enter or edit data in that column I do not get the benefit if the inputmask. I can enter any characters into the cell. Yet when I leave the cell it displays a message that the data entered into the cell is not the correctformat. So it is recognizing that the cell requires numeric data to be entered.I've used this same logic before with no problems, so I am perplexed why it's not working now. Any thoughts would be appreciated.
.Columns("LayerThicknessNbr").Format = "##0.0".Columns("LayerThicknessNbr").MaskInput = "nnn.n".Columns("LayerThicknessNbr").MaskDataMode = UltraWinMaskedEdit.MaskMode.Raw.Columns("LayerThicknessNbr").MaskDisplayMode = UltraWinMaskedEdit.MaskMode.IncludeBoth