Fired when a cell requires to format its caption.
![]() | Type | Description | ||
| Item as HITEM | A long expression that indicates the handle of the item being formatted. | |||
| ColIndex as Long | A long expression that indicates the index of the column being formatted. | |||
| Value as Variant | A Variant value that indicates the value being displayed in the cell. By default, the Value parameter is initialized with the CellValue property. |
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 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.
G2antt1.Columns("Freight").FireFormatColumn = True
G2antt1.Columns("Freight").HeaderBold = True
G2antt1.Columns("Freight").Alignment = RightAlignment
Private Sub G2antt1_FormatColumn(ByVal Item As EXG2ANTTLibCtl.HITEM, ByVal ColIndex As Long, Value As Variant)
Value = FormatCurrency(Value, 2) ' The FormatCurrency is a VB function
End Sub
if the sample looks like following:
G2antt1.Columns("Freight").FireFormatColumn = False
G2antt1.Columns("Freight").HeaderBold = True
G2antt1.Columns("Freight").Alignment = RightAlignment
For instance, you can use the FormatColumn event to display "Yes" or "No" caption for a boolean column. The following VB sample shows how to do it:
Private Sub G2antt1_FormatColumn(ByVal Item As EXG2ANTTLibCtl.HITEM, ByVal ColIndex As Long, Value As Variant) Value = IIf(Value < 50, "Yes", "No") End Sub
The following VB sample displays the result of adding ( concatenating ) of two cells:
Private Sub G2antt1_FormatColumn(ByVal Item As EXG2ANTTLibCtl.HITEM, ByVal ColIndex As Long, Value As Variant)
With G2antt1.Items
Value = .CellValue(Item, 0) + .CellValue(Item, 1)
End With
End Sub
The following C++ sample displays a date column using a format like "Saturday, January 31, 2004":
void OnFormatColumnG2antt1(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 AxG2antt1_FormatColumn(ByVal sender As Object, ByVal e As AxEXG2ANTTLib._IG2anttEvents_FormatColumnEvent) Handles AxG2antt1.FormatColumn
e.value = DateTime.Parse(e.value).ToLongDateString()
End Sub
The following C# sample displays a date column using LongDate format:
private void axG2antt1_FormatColumn(object sender, AxEXG2ANTTLib._IG2anttEvents_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.G2antt1.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.