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 を使用すると、ユーザーはグリッドの列に通貨値を簡単に入力できます。この機能は、C1FlexGrid の Column オブジェクトの Format プロパティで公開されます。このプロパティを使用すると、任意の整数型の列の形式を変更して通貨を表すことができます。通貨形式は、現在のロケール設定の影響を受けることがわかります。したがって、同じロケールの通貨を表示する必要があるシナリオでは、このプロパティが使用されます。

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

ただし、単一のグリッドで異なる通貨を使用するユースケースは数多くあります。OwnerDrawCell を使用すると、セル/列/行の Format 文字列を渡すだけで、この「制限」を回避できます。これを実現する次のスニペットを参照してください。

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

ここでサンプルを見つけてください: http://our.componentone.com/wp-content/uploads/2014/09/FlexGridCurrencyVB.zip

于 2014-09-19T06:42:31.887 に答える