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
Assuming that you are using the right column key here, then there's no reason why this code should not be working. My guess is that something that is occurring after this event it resetting these properties. Perhaps you are loading a Layout into the grid after this event fires?
That seems to indicate that either you are setting the Style to something else prior to this line of code, or else the data type of the column is not actually a numeric value.
That was my first thought, but I've re-checked the column key and it is correct. I finally got it to work by adding this.
.Columns("
LayerThicknessNbr").Style = UltraWinGrid.ColumnStyle.Double
Now it works. I never had to do that before. Thanks for your reply.