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. This basic property is proven useful in different scenarios. On a closer look, it is observed 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 invaluable. However, there are many use cases where different currencies are to be used in a single grid. Let us consider an example of any commodity export/import Manager. His requirements ask for costs of a single commodity in multiple currencies. Displaying different currencies in a single FlexGrid is not possible using the pre-defined currency formats. For an instance you may think,
C1FlexGrid comes with power packed features which have saved developers in many situations which on surface looked like a dead end. One such feature is OwnerDrawCellEvent which again comes to the rescue in here. 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
In the above snippet, the Format of the column is changed every time the value for the particular column is changed. Thus, the currency is displayed immediately after the cell value is edited.