0

我需要以货币格式在 C1FlexGird 中显示一个单元格,因此我试图创建一个具有货币格式的样式,并在为单元格赋值后应用该样式。加载网格时,单元格值不包含任何格式。谢谢你的帮助!

'Create Currency Style
Dim cs As C1.Win.C1FlexGrid.CellStyle
cs.DataType = GetType(String)
cs.Format = "c2"

'Set the value
fg(iRow, 1) = value

'Apply style to cell
 rg = fg.GetCellRange(iRow, 1)
 rg.Style = cs
4

1 回答 1

1

ComponentOne FlexGrid for WinForms facilitates users to enter currency values in the columns of the grid. This feature is exposed with the Format property of the Column object in C1FlexGrid. With this property, it is possible to change the format of any integer type column to represent currencies. It is seen that the currency format is subject to the current locale setting. Thus, for the scenarios where currencies for the same locale must be displayed, this property is used.

' Currency.
_flex.Cols(2).Format = "c"

However, there are many use cases where different currencies are to be used in a single grid. Using OwnerDrawCell, all you need is to pass the Format string for the cell/column/row, and you escape this “limitation” . Please refer to the following snippet which accomplishes this:

Private Sub _flex_OwnerDrawCell(sender As System.Object, e As OwnerDrawCellEventArgs) Handles _flex.OwnerDrawCell
 Select Case _flex.Cols(e.Col).Name
    Case "Pound"
        Try
            Dim i As Integer = CInt(Me._flex(e.Row, e.Col))
            e.Text = String.Format("{0:£#,##0}", i)
        Catch
        End Try
    Exit Select

    Case "Dollar"
        Try
            Dim i As Integer = CInt(Me._flex(e.Row, e.Col))
            e.Text = String.Format("{0:$#,##0}", i)
        Catch
        End Try
    Exit Select

    Case "Euro"
        Try
            Dim i As Integer = CInt(Me._flex(e.Row, e.Col))
            e.Text = String.Format("{0:€#,##0}", i)
        Catch
        End Try
    Exit Select

    Case "Yen/Yuan"
        Try
            Dim i As Integer = CInt(Me._flex(e.Row, e.Col))
            e.Text = String.Format("{0:¥#,##0}", i)
        Catch
        End Try
    Exit Select

    Case "Won"
        Try
            Dim i As Integer = CInt(Me._flex(e.Row, e.Col))
            e.Text = String.Format("{0:?#,##0}", i)
        Catch
        End Try
    Exit Select

    Case Else
    Exit Select

 End Select
End Sub

Find the sample here: http://our.componentone.com/wp-content/uploads/2014/09/FlexGridCurrencyVB.zip

于 2014-09-19T06:42:31.887 回答