property Items.CellForeColor(Index as Long, ColIndex as Variant) as Color
Retrieves or sets the cell's foreground color.

 TypeDescription 
   Index as Long A long expression that indicates the index of the item.  
   ColIndex as Variant A long expression that indicates the column's index or a string expression that indicates the column's name.  
   Color A color expression that indicates the cell's foreground color.  

Use the CellForeColor property to change the cell's foreground color. Use the ItemForeColor property to change the item's foreground color. Use the CellBackColor property to change the cell's background color. If the CellForeColor and ItemForeColor were not used, the cell uses the control's ForeColor property. Use the ClearCellForeColor property to clear the cell's foreground color when the CellForeColor property is used. Use the Def(exCellForeColor) property to specify the foreground color for all cells in a 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.

The following VB sample changes the foreground color for the focused cell:

With List1.Items
    .CellForeColor(.FocusItem, 0) = vbRed
End With

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

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 foreground color for the focused cell:

axList1.Items.set_CellForeColor(axList1.Items.FocusItem, 0, ToUInt32(Color.Red) );

The following VB.NET sample changes the foreground color for the focused cell:

With AxList1.Items
    .CellForeColor(.FocusItem, 0) = ToUInt32(Color.Red)
End With

The following C++ sample changes the foreground color for the focused cell:

#include "Items.h"
CItems items = m_list.GetItems();
items.SetCellForeColor( items.GetFocusItem(), COleVariant( (long)0 ), RGB(255,0,0) );

The following VFP sample changes the foreground color for the focused cell:

with thisform.List1.Items
	.CellForeColor( .FocusItem, 0 ) = RGB(255,0,0)
endwith

 


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