event FormatColumn (Item as HITEM, ColIndex as Long, Value as Variant)
Fired when a cell requires to format its value.

TypeDescription
Item as HITEM A long value that indicates the handle of the item being formatted
ColIndex as Long A long expression that indicates the column's index being formatted
Value as Variant A Variant value that should be converted.

Use the FormatColumn event to display a string different than the CellValue property. The FormatColumn event is fired only if the FireFormatColumn property of the Column is True. The FormatColumn event lets the user to provide the cell's caption before it is displayed on the control's list. For instance, the FormatColumn event is useful when the column cells contains prices( numbers ), and you want to display that column formatted as currency, like $50 instead 50. Also, you can use the FormatColumn event to display item's index in the column, or to display the result of some operations based on the cells in the item ( totals, currency conversion and so on ). The FormatCell property indicates the individually predefined format to be applied to particular cells. The FormatColumn property applies the predefined format for all cells in the columns.

The CellValue property of the cell is being shown as:

In other words, all cells applies the format of the FormatColumn property, excepts the cells with the FormatCell property being set. If the cell belongs to a column with the FireFormatColumn property on True, the Value parameter of the FormatColumn event shows the newly caption for the cell to be shown.

Syntax for FormatColumn event, /NET version, on:

private void FormatColumn(object sender,int Item,int ColIndex,ref object Value)
{
}

Private Sub FormatColumn(ByVal sender As System.Object,ByVal Item As Integer,ByVal ColIndex As Integer,ByRef Value As Object) Handles FormatColumn
End Sub

Syntax for FormatColumn event, /COM version, on:

private void FormatColumn(object sender, AxEXGRIDLib._IGridEvents_FormatColumnEvent e)
{
}

void OnFormatColumn(long Item,long ColIndex,VARIANT FAR* Value)
{
}

void __fastcall FormatColumn(TObject *Sender,Exgridlib_tlb::HITEM Item,long ColIndex,Variant * Value)
{
}

procedure FormatColumn(ASender: TObject; Item : HITEM;ColIndex : Integer;var Value : OleVariant);
begin
end;

procedure FormatColumn(sender: System.Object; e: AxEXGRIDLib._IGridEvents_FormatColumnEvent);
begin
end;

begin event FormatColumn(long Item,long ColIndex,any Value)
end event FormatColumn

Private Sub FormatColumn(ByVal sender As System.Object, ByVal e As AxEXGRIDLib._IGridEvents_FormatColumnEvent) Handles FormatColumn
End Sub

Private Sub FormatColumn(ByVal Item As EXGRIDLibCtl.HITEM,ByVal ColIndex As Long,Value As Variant)
End Sub

Private Sub FormatColumn(ByVal Item As Long,ByVal ColIndex As Long,Value As Variant)
End Sub

LPARAMETERS Item,ColIndex,Value

PROCEDURE OnFormatColumn(oGrid,Item,ColIndex,Value)
RETURN

Syntax for FormatColumn event, /COM version (others), on:

<SCRIPT EVENT="FormatColumn(Item,ColIndex,Value)" LANGUAGE="JScript">
</SCRIPT>

<SCRIPT LANGUAGE="VBScript">
Function FormatColumn(Item,ColIndex,Value)
End Function
</SCRIPT>

Procedure OnComFormatColumn HITEM llItem Integer llColIndex Variant llValue
	Forward Send OnComFormatColumn llItem llColIndex llValue
End_Procedure

METHOD OCX_FormatColumn(Item,ColIndex,Value) CLASS MainDialog
RETURN NIL

void onEvent_FormatColumn(int _Item,int _ColIndex,COMVariant /*variant*/ _Value)
{
}

function FormatColumn as v (Item as OLE::Exontrol.Grid.1::HITEM,ColIndex as N,Value as A)
end function

function nativeObject_FormatColumn(Item,ColIndex,Value)
return

The following VB sample formats the second column to display the values using the currency format:

Private Sub Form_Load()
With Grid1
    .BeginUpdate
    .Columns.Add "A"
    .Columns.Add("B").FireFormatColumn = True ' Index of it is 1
    With .Items
        .AddItem Array("One", 1)
        .AddItem Array("Two", 2)
    End With
    .EndUpdate
End With
End Sub

Private Sub Grid1_FormatColumn(ByVal Item As EXGRIDLibCtl.HITEM, ByVal ColIndex As Long, Value As Variant)
    Value = FormatCurrency(Value, 2, vbUseDefault)
End Sub

The following VB samples use the FormatCurrency function, to display a number as a currency. The FormatCurrency VB function returns an expression formatted as a currency value using the currency symbol defined in the system control panel.

Private Sub Grid1_FormatColumn(ByVal Item As EXGRIDLibCtl.HITEM, ByVal ColIndex As Long, Value As Variant)
    On Error Resume Next
    With Grid1
        Value = FormatCurrency(Value)
    End With
End Sub

The following VB sample formats a column that contains date values. The FormatDateTime function is a VB function that returns an expression formatted as a date or time:

Private Sub Grid1_FormatColumn(ByVal Item As EXGRIDLibCtl.HITEM, ByVal ColIndex As Long, Value As Variant)
    On Error Resume Next
    With Grid1
        Value = FormatDateTime(Value, vbLongDate)
    End With
End Sub

The following VB sample computes fields 1 + 2:

Private Sub Grid1_FormatColumn(ByVal Item As EXGRIDLibCtl.HITEM, ByVal ColIndex As Long, Value As Variant)
    ' Adds the first two columns, or concaternates the strings
    On Error Resume Next
    With Grid1.Items
        Value = .CellValue(Item) + .CellValue(Item, 1)
    End With
End Sub

The following C++ sample displays a date column using a format like "Saturday, March 10, 2004":

void OnFormatColumnGrid1(long Item, long ColIndex, VARIANT FAR* Value) 
{
	COleDateTime date( *Value );
	COleVariant vtNewValue( date.Format( _T("%A, %B %d, %Y") ) );
	VariantCopy( Value, vtNewValue );
}

The following VB.NET sample displays a date column using LongDate format:

Private Sub AxGrid1_FormatColumn(ByVal sender As Object, ByVal e As AxEXGRIDLib._IGridEvents_FormatColumnEvent) Handles AxGrid1.FormatColumn
    e.value = DateTime.Parse(e.value).ToLongDateString()
End Sub

The following C# sample displays a date column using LongDate format:

private void axGrid1_FormatColumn(object sender, AxEXGRIDLib._IGridEvents_FormatColumnEvent e)
{
	e.value = DateTime.Parse(e.value.ToString()).ToLongDateString();
}

The following VFP sample displays the item's index using the FormatColumn event:

*** ActiveX Control Event ***
LPARAMETERS item, colindex, value

with thisform.Grid1.Items
	.DefaultItem = item
	value = .ItemToIndex(0)
endwith

before running the sample please make sure that the :

application.AutoYield = .f.

is called during the Form.Init event.