none
Could we use NumberFormatInfo from CultureInfo for displaying the data? RRS feed

  • Question

  • Hi all.

    I'm using VB 2005 and localreport (.rdlc).

    What I try to do is to use NumberFormatInfo from CultureInfo for displaying the data, so I don't need to set the computer regional setting.

    On datagridview i could use This code :

    Code Snippet

    Imports System.Globalization
    ...
    Dim nfi As NumberFormatInfo = New CultureInfo("en-US", False).NumberFormat
    ....

    nfi.CurrencyDecimalSeparator = MyStringSeparator
    nfi.CurrencyGroupSeparator = MyStringGroup
    nfi.CurrencySymbol = MyStringSimbol
    ...

    Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
            If (DataGridView1.Columns(e.ColumnIndex).Name = "dgvPriceSold" Or DataGridView1.Columns(e.ColumnIndex).Name = "dgvTotal") AndAlso Not DataGridView1.Rows(e.RowIndex).IsNewRow Then
                If e.Value Is System.DBNull.Value Then
                    'do nothing
                Else
                    e.Value = CDec(e.Value).ToString("C", nfi)
                End If
         End If
    End Sub


    Could we do this in report?
    How we could do this?

    Thanks for any comment, idea, suggestion.

    Monday, September 3, 2007 7:46 AM

Answers

  •  

    First, look at the Report Properties dialog, there is a References tab.  It's got to be there for *something* .


    Second, in this case, you don't even need it, I don't think.  You should be able to do it like this:

     

    Code Snippet


    Public Function  MyTest() AS String

      Dim nfi As System.Globalization.NumberFormatInfo =
         New  System.Globalization.CultureInfo("en-US", False).NumberFormat
      Return nfi.GetType().ToString()

    End Function

     

     

    Check it out.  Tell me what you see.  Works for me in both RDL and RDLC...

     

    >L<

     

    Tuesday, September 4, 2007 3:45 AM

All replies

  • You should be able to do this in report code.  Did you try, and get an error?  What did you try, and what was the error that you got?

     

    You might want to supply the culture info ("en-US" in your example) as a parameter to the report.  Other than that, I am not sure what the problem would be.

     

    You can use an expression for the Format and I am not aware of any limitations on this that would not allow a report code function to supply the expression.  If it turns out that there is one, you could do the evaluation in a function that receives the value you wish to format, and return a fully-formated result as the Value rather than as the Format.

     


    >L<

     

    >L<

     

    Monday, September 3, 2007 5:24 PM
  • Thank for your reply Lisa.

    I'm also has thinking about using code, but as my limit knowledge know that to use CultureInfo we must import System.Globalization.And in code we cannot use import. That’s why I have this problem.


    So how we use this System.Globalization.CultureInfo?


    Tuesday, September 4, 2007 3:22 AM
  •  

    First, look at the Report Properties dialog, there is a References tab.  It's got to be there for *something* .


    Second, in this case, you don't even need it, I don't think.  You should be able to do it like this:

     

    Code Snippet


    Public Function  MyTest() AS String

      Dim nfi As System.Globalization.NumberFormatInfo =
         New  System.Globalization.CultureInfo("en-US", False).NumberFormat
      Return nfi.GetType().ToString()

    End Function

     

     

    Check it out.  Tell me what you see.  Works for me in both RDL and RDLC...

     

    >L<

     

    Tuesday, September 4, 2007 3:45 AM
  • Ok, I'm going to try it now. And I will inform the result.

    Thanks Lisa.
    Tuesday, September 4, 2007 3:57 AM
  • Thanks Lisa.

    It's work for my code.

       
    Code Snippet

    Public Function ConvertToMyCulture(ByVal Data As Decimal) As String
            Dim strResult As String = ""
            Dim nfi As System.Globalization.NumberFormatInfo = New System.Globalization.CultureInfo("en-US", False).NumberFormat
            nfi.CurrencyDecimalSeparator = MySeparator 'in string
            nfi.CurrencyGroupSeparator = MyGroupSeparator 'in string
            nfi.CurrencySymbol = MySymbol'in string
            strResult = Data.ToString("C", nfi)
            Return strResult
        End Function


    Tuesday, September 4, 2007 5:02 AM