Retrieves or sets the cell's background color.
![]() | Type | Description | ||
| 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 following VB sample changes the cell's appearance. The sample uses the
"
"
skin to mark a cell:
With Grid1
With .VisualAppearance
.Add &H40, App.Path + "\cell.ebn"
End With
With .Items
.CellBackColor(.FirstVisibleItem, 0) = &H40000000
End With
End With
The following C++ sample changes the cell's appearance:
#include "Appearance.h"
#include "Items.h"
m_grid.GetVisualAppearance().Add( 0x40, COleVariant(_T("D:\\Temp\\ExGrid.Help\\cell.ebn")) );
m_grid.GetItems().SetCellBackColor( COleVariant( m_grid.GetItems().GetFirstVisibleItem() ), COleVariant( long(0) ), 0x40000000 );
The following VB.NET sample changes the cell's appearance.
With AxGrid1
With .VisualAppearance
.Add(&H40, "D:\Temp\ExGrid.Help\cell.ebn")
End With
With .Items
.CellBackColor(.FirstVisibleItem, 0) = &H40000000
End With
End With
The following C# sample changes the cell's appearance.
axGrid1.VisualAppearance.Add(0x40, "D:\\Temp\\ExGrid.Help\\cell.ebn"); axGrid1.Items.set_CellBackColor(axGrid1.Items.FirstVisibleItem, 0, 0x40000000);
The following VFP sample changes the cell's appearance.
With thisform.Grid1
With .VisualAppearance
.Add(64, "D:\Temp\ExGrid.Help\cell.ebn")
EndWith
with .Items
.DefaultItem = .FirstVisibleItem
.CellBackColor(0,0) = 1073741824
endwith
EndWith
In VB.NET or C# you require the following functions until the .NET framework will support them:
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
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 focused cell:
axGrid1.Items.set_CellBackColor(axGrid1.Items.FocusItem, axGrid1.FocusColumnIndex, ToUInt32(Color.Red));
The following VB.NET sample changes the background color for the focused cell:
With AxGrid1.Items
.CellBackColor(.FocusItem, AxGrid1.FocusColumnIndex) = ToUInt32(Color.Red)
End With
The following C++ sample changes the background color for the focused cell:
#include "Items.h" CItems items = m_grid.GetItems(); items.SetCellBackColor( COleVariant( items.GetFocusItem() ), COleVariant( m_grid.GetFocusColumnIndex() ), RGB(255,0,0) );
The following VB sample changes the background color for the focused cell:
With Grid1.Items
.CellBackColor(.FocusItem, Grid1.FocusColumnIndex) = vbRed
End With
The following VFP sample changes the background color for the focused cell:
with thisform.Grid1.Items .DefaultItem = .FocusItem .CellBackColor( 0, thisform.Grid1.FocusColumnIndex ) = 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 Grid1 .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), Grid1.Columns(0).Caption) = True End With
Send comments on this topic. © 1999-2008 Exontrol Inc, Software. All rights reserved.