property Items.CellBackColor([Item as Variant], [ColIndex as Variant]) as Color

Retrieves or sets the cell's background color.

 TypeDescription 
   Item as Variant A long expression that indicates the item's handle.  
   ColIndex as Variant A long expression that indicates the cell's handle or the column's index, a string expression that indicates the column's caption or the column's key.  
   Color A color expression that indicates the cell's background color. The last 7 bits in the high significant byte of the color to indicates the identifier of the skin being used. Use the Add method to add new skins to the control. If you need to remove the skin appearance from a part of the control you need to reset the last 7 bits in the high significant byte of the color being applied to the background's part.  

To change the background color for the entire item you can use ItemBackColor property. Use the ClearCellBackColor method to clear the cell's background color. Use the BackColor property to specify the control's background color. Use the CellForeColor property to specify the cell's foreground color. Use the ItemForeColor property to specify the item's foreground color. Use the Def(exCellBackColor) property to specify the background color for all cells in the column. Use the ConditionalFormats method to apply formats to a cell or range of cells, and have that formatting change depending on the value of the cell or the value of a formula.

In VB.NET or C# you require the following functions until the .NET framework will support them:

You can use the following VB.NET function:
     Shared Function ToUInt32(ByVal c As Color) As UInt32
         Dim i As Long
	 i = c.R
	 i = i + 256 * c.G
	 i = i + 256 * 256 * c.B
	 ToUInt32 = Convert.ToUInt32(i)
     End Function 
You can use the following C# function:
private UInt32 ToUInt32(Color c)
{
	long i;
	i = c.R;
	i = i + 256 * c.G;
	i = i + 256 * 256 * c.B;
	return Convert.ToUInt32(i);
}

The following C# sample changes the background color for the first cell:

axComboBox1.Items.set_CellBackColor(axComboBox1.Items.FirstVisibleItem, axComboBox1.SearchColumnIndex, ToUInt32(Color.Red));

The following VB.NET sample changes the background color for the first cell:

With AxComboBox1.Items
    .CellBackColor(.FirstVisibleItem, AxComboBox1.SearchColumnIndex) = ToUInt32(Color.Red)
End With

The following C++ sample changes the background color for the first cell:

#include "Items.h"
CItems items = m_combobox.GetItems();
items.SetCellBackColor( COleVariant( items.GetFirstVisibleItem() ), COleVariant( m_combobox.GetSearchColumnIndex() ), RGB(255,0,0) );

The following VB sample changes the background color for the first cell:

With ComboBox1.Items
    .CellBackColor(.FirstVisibleItem, ComboBox1.SearchColumnIndex) = vbRed
End With

The following VFP sample changes the background color for the first cell:

with thisform.ComboBox1.Items
	.DefaultItem = .FirstVisibleItem
	.CellBackColor( 0, thisform.ComboBox1.SearchColumnIndex ) = RGB(255,0,0)
endwith

Note: The intersection of an item with a column defines a cell. Each cell is uniquely represented by its handle. The cell's handle is of HCELL type, that's equivalent with a long type. All properties of Items object that have two parameters Item and ColIndex, refer a cell.

The following lines are equivalents and each of them changes the bold font attribute of the first cell on the first item.

With ComboBox1
    .Items.CellBold(, .Items.ItemCell(.Items(0), 0)) = True
    .Items.CellBold(.Items(0), 0) = True
    .Items.CellBold(.Items(0)) = True
    .Items.CellBold(.Items.ItemByIndex(0)) = True
    .Items.CellBold(.Items.ItemByIndex(0), 0) = True
    .Items.CellBold(.Items(0), ComboBox1.Columns(0).Caption) = True
End With


Send comments on this topic.
1999-2017 Exontrol.COM, Software. All rights reserved.