Step 2: Data Formatting

When displaying numeric or date values, you will typically want to adopt a consistent format for the values. The VSFlexGrid allows you to do this using the ColFormat property. This property allows you to assign a format to each column. The formats are similar to the ones recognized by the Visual Basic Format function.

The ColFormat property must be assigned at run time. A good place to do it is in the Form_Load event, as show below:

   Private Sub Form_Load()

   

       ' format column 3 (Amount Sold) to display currency

        fg.ColFormat(3) = "$#,###.00"

   

   End Sub

This code assigns a format to column 3 (Amount Sold). The format specifies that values should be displayed with a currency sign, thousand separators, and two decimals.

The ColFormat property does not affect the cell content, only the way it is displayed. You may change the format freely without modifying the underlying data.