Retrieves or sets the cell's foreground 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 foreground color |
For instance, the following VB code changes the left top cell of your control: Grid1.Items.CellForeColor(Grid1.Items(0), 0) = vbBlue
In VB.NET or C# you require the following functions until the .NET framework will provide:
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 VB sample changes the foreground color for the focused cell:
With Grid1.Items
.CellForeColor(.FocusItem, Grid1.FocusColumnIndex) = vbRed
End With
The following C# sample changes the foreground color for the focused cell:
axGrid1.Items.set_CellForeColor(axGrid1.Items.FocusItem, axGrid1.FocusColumnIndex, ToUInt32(Color.Red));
The following VB.NET sample changes the foreground color for the focused cell:
With AxGrid1.Items
.CellForeColor(.FocusItem, AxGrid1.FocusColumnIndex) = ToUInt32(Color.Red)
End With
The following C++ sample changes the foreground color for the focused cell:
#include "Items.h" CItems items = m_grid.GetItems(); items.SetCellForeColor( COleVariant( items.GetFocusItem() ), COleVariant( (long)m_grid.GetFocusColumnIndex() ), RGB(255,0,0) );
The following VFP sample changes the foreground color for the focused cell:
with thisform.Grid1.Items .DefaultItem = .FocusItem .CellForeColor( 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.