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 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 focused cell:

axG2antt1.Items.set_CellBackColor(axG2antt1.Items.FocusItem, 0, ToUInt32(Color.Red));

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

With AxG2antt1.Items
    .CellBackColor(.FocusItem, 0) = ToUInt32(Color.Red)
End With

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

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

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

with thisform.G2antt1.Items
	.DefaultItem = .FocusItem
	.CellBackColor( 0, 0 ) = RGB(255,0,0)
endwith

For instance, the following VB code changes background color of the left top cell of your control: G2antt1.Items.CellBackColor(G2antt.Items(0), 0) = vbBlue 

Note: A cell is the intersection of an item with a column. All properties that has an Item and a ColIndex parameters are referring to a cell. The Item parameter represents the handle of an item, and the ColIndex parameter indicates an index ( a numerical value, see Column.Index property ) of a column , the column's caption ( a string value, see Column.Caption property ), or a handle to a cell ( see ItemCell property ). Here's few hints how to use properties with Item and ColIndex parameters:

G2antt1.Items.CellBold(, G2antt1.Items.ItemCell(G2antt1.Items(0), 0)) = True

G2antt1.Items.CellBold(G2antt1.Items(0), 0) = True

G2antt1.Items.CellBold(G2antt1.Items(0), "ColumnName") = True


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