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.
so i think you hinted something that gave me an idea that was the issue. I went back and looked at my datasource, The columns was not the correct datatype. Thanks for your help!
Hm, it's hard to follow what's going on from just a snippet of code like this.
What's the DataType of the grid column that is not working?
Try setting the Format property on the column. Maybe the cell format doesn't work unless there is also a column format.
If that doesn't help, can you put together a small sample project with just a simple grid with a column of the same DataType and see if it works with the same code you have here? Maybe there is something missing that you need to do that isn't obvious from my sample. If I have a sample to work with, I'm sure I could figure out why it's not working.
The sample application you sent works and works great. I also tried using the UltraNumericEditor object and set the cell's editor component to the new editor. I thought that might change the something, but the formatting does not work. It always comes out as an integer. I tried changing the NumerType to Decimal/Double. The same thing happens, always comes out as an Integer. I thought the editor at some might change, but when I set the property, MASKINPUT, the mask does generate, and the format does change, but there are no literals when I set up the format to have the '$' sign. In the InitializeLayout event function, I am looking at a list of objects and the function determines what type of cell needs to be created (date/text/dropdown/number) for that particular column. When I create an UltraDateEditor, the format that I set comes out correctly, but not the UltraNumeric Editor.
For Each oParam As Parameter In _parameters
Select Case oParam.DataTypeCase DataType.DateType
Dim udte As New UltraDateTimeEditor
uRow.Cells(oParam.DisplayName).EditorComponent = udteudte.Value = uRow.Cells(oParam.DisplayName).Valueudte.FormatString = oParam.FormatValue
If oParam.MinValue IsNot Nothing Thenudte.MinDate = oParam.MinValueEnd IfIf oParam.MaxValue IsNot Nothing Thenudte.MaxDate = oParam.MaxValueEnd If
uRow.Cells(oParam.DisplayName).Column.Style = ColumnStyle.DateTimeWithoutDropDownuRow.Cells(oParam.DisplayName).Tag = _paramTypeList.Find(Function(en) en.ParameterID = oParam.ID And en.Seq = ugParameters.Rows.Count)
Case DataType.DropdownDim vList As ValueList = New ValueList()Dim strNArray() As StringDim strVArray() As StringDim strSQL As String = ""vList.ValueListItems.Add("", "")strSQL = oParam.ItemSQLIf strSQL <> "" ThenDim strName = oParam.ItemNamesDim strValue = oParam.ItemValues
Dim results As DataSet = loadItemsFromDB(strSQL)
If results IsNot Nothing ThenFor Each oRow As DataRow In results.Tables(0).RowsvList.ValueListItems.Add(oRow.Item(strValue), oRow.Item(strName))NextEnd IfElsestrNArray = oParam.ItemNames.Split(",")strVArray = oParam.ItemValues.Split(",")Dim idx As IntegerIf strNArray.Count = strVArray.Count ThenFor idx = 0 To strNArray.Count - 1vList.ValueListItems.Add(strVArray(idx), strNArray(idx))NextEnd If
End IfuRow.Cells(oParam.DisplayName).ValueList = vListDim t As ParamType = _paramTypeList.Find(Function(en) en.ParameterID = oParam.ID And en.Seq = ugParameters.Rows.Count)uRow.Cells(oParam.DisplayName).Tag = tuRow.Cells(oParam.DisplayName).Style = ColumnStyle.DropDownValidate
Case DataType.NumberDim une As New UltraNumericEditoruRow.Cells(oParam.DisplayName).EditorComponent = uneune.MinValue = oParam.MinValueune.MaxValue = oParam.MaxValueune.NumericType = NumericType.Integerune.FormatString = oParam.FormatValueune.MaskDisplayMode = UltraWinMaskedEdit.MaskMode.IncludeLiteralsune.MaskInput = oParam.FormatValueune.Nullable = True
uRow.Cells(oParam.DisplayName).Tag = _paramTypeList.Find(Function(en) en.ParameterID = oParam.ID And en.Seq = ugParameters.Rows.Count)
Case DataType.TextTypeuRow.Cells(oParam.DisplayName).Tag = _paramTypeList.Find(Function(en) en.ParameterID = oParam.ID And en.Seq = ugParameters.Rows.Count)End Select
Next
Why does the Date Cell format correctly and the Numeric Cell Format does not? Maybe I am missing something?
Maybe there is a better place to create the cells?
Does it work when you run my sample? If so, then there must be something different in your application that is causing it not to work.
The obvious pitfalls would be that the column is the wrong data type. Or that something else is setting the editor on that column after you set it with the code you have here and thus it's getting removed. Maybe you are loading a layout and that's blowing away the editor.
I followed the sample code you gave me, but I was still unable to get it to show the format I want.
The code below is similar to the sample. The segment below runs through when the InitializeLayout Event is created:
Dim settings As New DefaultEditorOwnerSettings()settings.Format = "$#,##0.00"settings.MaskInput = "C"settings.MaskDisplayMode = Infragistics.Win.UltraWinMaskedEdit.MaskMode.IncludeLiterals
Dim editorOwner As New DefaultEditorOwner(settings)
Dim editor As New EditorWithText(editorOwner)uRow.Cells(oParam.DisplayName).Editor = editor
It still shows the number as an integer not as currency.