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. The HTML colors are not applied if the item is selected. Use the SelectedItem property to specify whether an item is selected or unselected. Use the Def(exCellBackColor) property to specify the background color for all cells in the column. Use the Add method to add new skins to the control. You can define new skins and to use it to mark some cells, like in the following samples. 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 cell's appearance. The sample uses the "" skin to mark a cell:

With Tree1
    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_tree.GetVisualAppearance().Add( 0x40, COleVariant(_T("D:\\Temp\\ExTree.Help\\cell.ebn")) );
m_tree.GetItems().SetCellBackColor( COleVariant( m_tree.GetItems().GetFirstVisibleItem() ), COleVariant( long(0) ), 0x40000000 );

The following VB.NET sample changes the cell's appearance.

With AxTree1
    With .VisualAppearance
        .Add(&H40, "D:\Temp\ExTree.Help\cell.ebn")
    End With
    With .Items
        .CellBackColor(.FirstVisibleItem, 0) = &H40000000
    End With
End With

The following C# sample changes the cell's appearance.

axTree1.VisualAppearance.Add(0x40, "D:\\Temp\\ExTree.Help\\cell.ebn");
axTree1.Items.set_CellBackColor(axTree1.Items.FirstVisibleItem, 0, 0x40000000);

The following VFP sample changes the cell's appearance.

With thisform.Tree1
    With .VisualAppearance
        .Add(64, "D:\Temp\ExTree.Help\cell.ebn")
    EndWith
    with .Items
    	.DefaultItem = .FirstVisibleItem
    	.CellBackColor(0,0) = 1073741824
    endwith
EndWith

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

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

where the ToUInt32 function converts a Color expression to an OLE_COLOR expression:

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.NET sample changes the background color for the focused cell:

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

where the ToUInt32 function converts a Color expression to an OLE_COLOR expression:

     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 

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

#include "Items.h"
CItems items = m_tree.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.Tree1.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: Tree1.Items.CellBackColor(Tree.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:

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

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

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


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