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 | (By Reference) A Variant value that indicates the value being displayed in the cell. By default, the Value parameter is initialized with the CellCaption property. |
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.
ComboBox1.Columns("Freight").FireFormatColumn = True ComboBox1.Columns("Freight").HeaderBold = True ComboBox1.Columns("Freight").Alignment = RightAlignment
Private Sub ComboBox1_FormatColumn(ByVal Item As EXCOMBOBOXLibCtl.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:
ComboBox1.Columns("Freight").FireFormatColumn = False ComboBox1.Columns("Freight").HeaderBold = True ComboBox1.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 ComboBox1_FormatColumn(ByVal Item As EXCOMBOBOXLibCtl.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 ComboBox1_FormatColumn(ByVal Item As EXCOMBOBOXLibCtl.HITEM, ByVal ColIndex As Long, Value As Variant) With ComboBox1.Items Value = .CellCaption(Item, 0) + .CellCaption(Item, 1) End With End Sub
The following C++ sample displays a date column using a format like "Saturday, January 31, 2004":
void OnFormatColumnComboBox1(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 AxComboBox1_FormatColumn(ByVal sender As Object, ByVal e As AxEXCOMBOBOXLib._IComboBoxEvents_FormatColumnEvent) Handles AxComboBox1.FormatColumn e.value = DateTime.Parse(e.value).ToLongDateString() End Sub
The following C# sample displays a date column using LongDate format:
private void axComboBox1_FormatColumn(object sender, AxEXCOMBOBOXLib._IComboBoxEvents_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.ComboBox1.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.
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 |
private void FormatColumn(object sender, AxEXCOMBOBOXLib._IComboBoxEvents_FormatColumnEvent e) { } void OnFormatColumn(long Item,long ColIndex,VARIANT FAR* Value) { } void __fastcall FormatColumn(TObject *Sender,Excomboboxlib_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: AxEXCOMBOBOXLib._IComboBoxEvents_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 AxEXCOMBOBOXLib._IComboBoxEvents_FormatColumnEvent) Handles FormatColumn End Sub Private Sub FormatColumn(ByVal Item As EXCOMBOBOXLibCtl.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(oComboBox,Item,ColIndex,Value) RETURN |
<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.ComboBox.1::HITEM,ColIndex as N,Value as A) end function function nativeObject_FormatColumn(Item,ColIndex,Value) return |