Type | Description | |||
Item as Variant | A long expression that indicates the item's handle. | |||
ColIndex as Variant |
A long expression that indicates the column's index, or a string expression that indicates the column's caption or the column's key. | |||
IFontDisp | A Font object that indicates the item's font. |
By default, the CellFont property is nothing. If the CellFont property is noting, the cell uses the item's font. Use the CellFont and ItemFont properties to specify different fonts for cells or items. Use the CellBold, CellItalic, CellUnderline, CellStrikeout, ItemBold, ItemUnderline, ItemStrikeout, ItemItalic or CellCaptionFormat to specify different font attributes. Use the BeginUpdate and EndUpdate methods if you are doing multiple changes, so no need for an update each time a change is done.
The following VB sample changes the font for the focused cell:
ComboBox1.BeginUpdate With ComboBox1.Items .CellFont(.FocusItem, 0) = ComboBox1.Font With .CellFont(.FocusItem, 0) .Name = "Comic Sans MS" .Size = 10 .Bold = True End With End With ComboBox1.EndUpdate
The following C++ sample changes the font for the focused cell:
#include "Items.h" #include "Font.h" m_combobox.BeginUpdate(); CItems items = m_combobox.GetItems(); COleVariant vtItem(items.GetFocusItem()), vtColumn( (long)0 ); items.SetCellFont( vtItem, vtColumn, m_combobox.GetFont().m_lpDispatch ); COleFont font = items.GetCellFont( vtItem, vtColumn ); font.SetName( "Comic Sans MS" ); font.SetBold( TRUE ); m_combobox.EndUpdate();
The following VB.NET sample changes the font for the focused cell:
AxComboBox1.BeginUpdate() With AxComboBox1.Items .CellFont(.FocusItem, 0) = IFDH.GetIFontDisp(AxComboBox1.Font) With .CellFont(.FocusItem, 0) .Name = "Comic Sans MS" .Bold = True End With End With AxComboBox1.EndUpdate()
where the IFDH class is defined like follows:
Public Class IFDH Inherits System.Windows.Forms.AxHost Sub New() MyBase.New("") End Sub Public Shared Function GetIFontDisp(ByVal font As Font) As Object GetIFontDisp = AxHost.GetIFontFromFont(font) End Function End Class
The following C# sample changes the font for the focused cell:
axComboBox1.BeginUpdate(); axComboBox1.Items.set_CellFont(axComboBox1.Items.FocusItem, 0, IFDH.GetIFontDisp(axComboBox1.Font)); stdole.IFontDisp spFont = axComboBox1.Items.get_CellFont(axComboBox1.Items.FocusItem, 0); spFont.Name = "Comic Sans MS"; spFont.Bold = true; axComboBox1.EndUpdate();
where the IFDH class is defined like follows:
internal class IFDH : System.Windows.Forms.AxHost { public IFDH() : base("") { } public static stdole.IFontDisp GetIFontDisp(System.Drawing.Font font) { return System.Windows.Forms.AxHost.GetIFontFromFont(font) as stdole.IFontDisp; } }
The following VFP sample changes the font for the focused cell:
thisform.ComboBox1.BeginUpdate() with thisform.ComboBox1.Items .DefaultItem = .FocusItem .CellFont(0,0) = thisform.ComboBox1.Font with .CellFont(0,0) .Name = "Comic Sans MS" .Bold = .t. endwith endwith thisform.ComboBox1.EndUpdate()