I am trying to get the cell to format. The requirement is the application needs to be able to handle different types of formats. The formats will come from a database so the cells are going to built dynamically. No matter what formatting I use, it always comes out as an integer. I reviewed Microsoft's documentation on numeric formatting, but with no luck.
I want options for formatting for currency, decimal with two digits after the period, integer, and percent.
Here is my code that builds a UltraNumericEditor
Case DataType.TextType
Dim une As UltraNumericEditor = New UltraNumericEditor
With une.Nullable = True.MaskDisplayMode = UltraWinMaskedEdit.MaskMode.Raw.MinValue = oParam.MinValue.MaxValue = oParam.MaxValueEnd With
'Assign it to the Cell.EditorWith uRow.Cells(oParam.DisplayName).EditorComponent = uneEnd WithuRow.Cells(oParam.DisplayName).Column.Format = "###.##" ' "#####" "##%" uRow.Cells(oParam.DisplayName).Tag = _paramTypeList.Find(Function(en) en.ParameterID = oParam.ID And en.Seq = ugParameters.Rows.Count)
Hi Peter,
I'm not exactly 100% clear on what you are trying to do. If you want to format a column, then all you have to do is set the Format property on the column. The column's DataType has to be numeric, of course - you cannot format a string type.
The code you have here is jumping through a lot of seemingly unnecessary hoops by creating and assigning an editor. Also, you seem to be getting the column via the cell, which is a very strange way to do things. The Column property on the Cell is a backward pointer to the column object - it's not a sub-object of the cell that only affects that cell. So you are not assigning a cell-specific settings here. In other words, these three lines of code are functionally identical.
uRow.Cells(oParam.DisplayName).Column.Format = "###.##" ' "#####" "##%"
uRow.Band.Columns(oParam.DisplayName).Format = "###.##" ' "#####" "##%"
grid.DisplayLayout.Bands(0).Columns(oParam.DisplayName).Format = "###.##" ' "#####" "##%"
If you want to set the Format on an individual cell, it's a bit more complicated and you do need to use an editor for that. You would need one editor for each potential format and then apply the appropriate editor with the appropriate format to the cell. Is that what you want?
I found an old sample I wrote that demonstrates how to have different formats in the same column for different rows. The sample is in C# and not VB, but it should get you started. Let me know fi you have any trouble translating it or have any questions.