Skip to content

Infragistics Community Forum / Desktop / Ultimate UI for Windows Forms / UltraGridCell Formatting in vb.net

UltraGridCell Formatting in vb.net

New Discussion
Peter
Peter asked on Oct 11, 2017 4:14 PM

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.MaxValue
End With

‘Assign it to the Cell.Editor
With uRow
.Cells(oParam.DisplayName).EditorComponent = une
End With
uRow.Cells(oParam.DisplayName).Column.Format =  “###.##” ‘ “#####”  “##%”
uRow.Cells(oParam.DisplayName).Tag = _paramTypeList.Find(Function(en) en.ParameterID = oParam.ID And en.Seq = ugParameters.Rows.Count)

Sign In to post a reply

Replies

  • 0
    Mike Saltzman
    Mike Saltzman answered on Oct 4, 2017 8:23 PM

    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?

    uRow.Cells(oParam.DisplayName).Column.Format =  "###.##" ' "#####"  "##%" 

    • 0
      Mike Saltzman
      Mike Saltzman answered on Oct 4, 2017 8:29 PM

      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.

      • 0
        Peter
        Peter answered on Oct 9, 2017 7:52 PM

        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.

      • 0
        Mike Saltzman
        Mike Saltzman answered on Oct 10, 2017 2:28 PM

        Hi Peter, 

        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. 

      • 0
        Peter
        Peter answered on Oct 10, 2017 3:42 PM

        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.DataType
        Case DataType.DateType

        Dim udte As New UltraDateTimeEditor

        uRow.Cells(oParam.DisplayName).EditorComponent = udte
        udte.Value = uRow.Cells(oParam.DisplayName).Value
        udte.FormatString = oParam.FormatValue

        If oParam.MinValue IsNot Nothing Then
        udte.MinDate = oParam.MinValue
        End If
        If oParam.MaxValue IsNot Nothing Then
        udte.MaxDate = oParam.MaxValue
        End If

        uRow.Cells(oParam.DisplayName).Column.Style = ColumnStyle.DateTimeWithoutDropDown
        uRow.Cells(oParam.DisplayName).Tag = _paramTypeList.Find(Function(en) en.ParameterID = oParam.ID And en.Seq = ugParameters.Rows.Count)

        Case DataType.Dropdown
        Dim vList As ValueList = New ValueList()
        Dim strNArray() As String
        Dim strVArray() As String
        Dim strSQL As String = ""
        vList.ValueListItems.Add("", "")
        strSQL = oParam.ItemSQL
        If strSQL <> "" Then
        Dim strName = oParam.ItemNames
        Dim strValue = oParam.ItemValues

        Dim results As DataSet = loadItemsFromDB(strSQL)

        If results IsNot Nothing Then
        For Each oRow As DataRow In results.Tables(0).Rows
        vList.ValueListItems.Add(oRow.Item(strValue), oRow.Item(strName))
        Next
        End If
        Else
        strNArray = oParam.ItemNames.Split(",")
        strVArray = oParam.ItemValues.Split(",")
        Dim idx As Integer
        If strNArray.Count = strVArray.Count Then
        For idx = 0 To strNArray.Count – 1
        vList.ValueListItems.Add(strVArray(idx), strNArray(idx))
        Next
        End If

        End If
        uRow.Cells(oParam.DisplayName).ValueList = vList
        Dim t As ParamType = _paramTypeList.Find(Function(en) en.ParameterID = oParam.ID And en.Seq = ugParameters.Rows.Count)
        uRow.Cells(oParam.DisplayName).Tag = t
        uRow.Cells(oParam.DisplayName).Style = ColumnStyle.DropDownValidate

        Case DataType.Number
        Dim une As New UltraNumericEditor
        uRow.Cells(oParam.DisplayName).EditorComponent = une
        une.MinValue = oParam.MinValue
        une.MaxValue = oParam.MaxValue
        une.NumericType = NumericType.Integer
        une.FormatString = oParam.FormatValue
        une.MaskDisplayMode = UltraWinMaskedEdit.MaskMode.IncludeLiterals
        une.MaskInput = oParam.FormatValue
        une.Nullable = True

        uRow.Cells(oParam.DisplayName).Tag = _paramTypeList.Find(Function(en) en.ParameterID = oParam.ID And en.Seq = ugParameters.Rows.Count)

        Case DataType.TextType
        uRow.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?

      • 0
        Mike Saltzman
        Mike Saltzman answered on Oct 10, 2017 3:54 PM

        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. 

      • 0
        Peter
        Peter answered on Oct 11, 2017 4:14 PM

        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!

  • You must be logged in to reply to this topic.
Discussion created by
Favorites
Replies
Created On
Last Post
Discussion created by
Peter
Favorites
0
Replies
7
Created On
Oct 11, 2017
Last Post
9 years ago

Suggested Discussions

Created by

Created on

Oct 11, 2017 4:14 PM

Last activity on

Feb 20, 2026 11:37 AM